blob: bbb1187ac199434c5bfcfae285b48e4049aa55a1 [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 Moolenaarcfbc5ee2004-07-02 15:38:35 +00001926 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1927#ifdef FEAT_TEXTOBJ
1928 (char_u *)&p_qe, PV_QE,
1929 {(char_u *)"\\", (char_u *)0L}
1930#else
1931 (char_u *)NULL, PV_NONE,
1932 {(char_u *)NULL, (char_u *)0L}
1933#endif
1934 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1936 (char_u *)&p_ro, PV_RO,
1937 {(char_u *)FALSE, (char_u *)0L}},
1938 {"redraw", NULL, P_BOOL|P_VI_DEF,
1939 (char_u *)NULL, PV_NONE,
1940 {(char_u *)FALSE, (char_u *)0L}},
1941 {"remap", NULL, P_BOOL|P_VI_DEF,
1942 (char_u *)&p_remap, PV_NONE,
1943 {(char_u *)TRUE, (char_u *)0L}},
1944 {"report", NULL, P_NUM|P_VI_DEF,
1945 (char_u *)&p_report, PV_NONE,
1946 {(char_u *)2L, (char_u *)0L}},
1947 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1948#ifdef WIN3264
1949 (char_u *)&p_rs, PV_NONE,
1950#else
1951 (char_u *)NULL, PV_NONE,
1952#endif
1953 {(char_u *)TRUE, (char_u *)0L}},
1954 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
1955#ifdef FEAT_RIGHTLEFT
1956 (char_u *)&p_ri, PV_NONE,
1957#else
1958 (char_u *)NULL, PV_NONE,
1959#endif
1960 {(char_u *)FALSE, (char_u *)0L}},
1961 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
1962#ifdef FEAT_RIGHTLEFT
1963 (char_u *)VAR_WIN, PV_RL,
1964#else
1965 (char_u *)NULL, PV_NONE,
1966#endif
1967 {(char_u *)FALSE, (char_u *)0L}},
1968 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1969#ifdef FEAT_RIGHTLEFT
1970 (char_u *)VAR_WIN, PV_RLC,
1971 {(char_u *)"search", (char_u *)NULL}
1972#else
1973 (char_u *)NULL, PV_NONE,
1974 {(char_u *)NULL, (char_u *)0L}
1975#endif
1976 },
1977 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1978#ifdef FEAT_CMDL_INFO
1979 (char_u *)&p_ru, PV_NONE,
1980#else
1981 (char_u *)NULL, PV_NONE,
1982#endif
1983 {(char_u *)FALSE, (char_u *)0L}},
1984 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1985#ifdef FEAT_STL_OPT
1986 (char_u *)&p_ruf, PV_NONE,
1987#else
1988 (char_u *)NULL, PV_NONE,
1989#endif
1990 {(char_u *)"", (char_u *)0L}},
1991 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
1992 (char_u *)&p_rtp, PV_NONE,
1993 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
1994 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
1995 (char_u *)VAR_WIN, PV_SCROLL,
1996 {(char_u *)12L, (char_u *)0L}},
1997 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
1998#ifdef FEAT_SCROLLBIND
1999 (char_u *)VAR_WIN, PV_SCBIND,
2000#else
2001 (char_u *)NULL, PV_NONE,
2002#endif
2003 {(char_u *)FALSE, (char_u *)0L}},
2004 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2005 (char_u *)&p_sj, PV_NONE,
2006 {(char_u *)1L, (char_u *)0L}},
2007 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2008 (char_u *)&p_so, PV_NONE,
2009 {(char_u *)0L, (char_u *)0L}},
2010 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2011#ifdef FEAT_SCROLLBIND
2012 (char_u *)&p_sbo, PV_NONE,
2013 {(char_u *)"ver,jump", (char_u *)0L}
2014#else
2015 (char_u *)NULL, PV_NONE,
2016 {(char_u *)0L, (char_u *)0L}
2017#endif
2018 },
2019 {"sections", "sect", P_STRING|P_VI_DEF,
2020 (char_u *)&p_sections, PV_NONE,
2021 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
2022 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2023 (char_u *)&p_secure, PV_NONE,
2024 {(char_u *)FALSE, (char_u *)0L}},
2025 {"selection", "sel", P_STRING|P_VI_DEF,
2026#ifdef FEAT_VISUAL
2027 (char_u *)&p_sel, PV_NONE,
2028#else
2029 (char_u *)NULL, PV_NONE,
2030#endif
2031 {(char_u *)"inclusive", (char_u *)0L}},
2032 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2033#ifdef FEAT_VISUAL
2034 (char_u *)&p_slm, PV_NONE,
2035#else
2036 (char_u *)NULL, PV_NONE,
2037#endif
2038 {(char_u *)"", (char_u *)0L}},
2039 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2040#ifdef FEAT_SESSION
2041 (char_u *)&p_ssop, PV_NONE,
2042 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
2043 (char_u *)0L}
2044#else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)0L, (char_u *)0L}
2047#endif
2048 },
2049 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2050 (char_u *)&p_sh, PV_NONE,
2051 {
2052#ifdef VMS
2053 (char_u *)"-",
2054#else
2055# if defined(MSDOS)
2056 (char_u *)"command",
2057# else
2058# if defined(WIN16)
2059 (char_u *)"command.com",
2060# else
2061# if defined(WIN3264)
2062 (char_u *)"", /* set in set_init_1() */
2063# else
2064# if defined(OS2)
2065 (char_u *)"cmd.exe",
2066# else
2067# if defined(ARCHIE)
2068 (char_u *)"gos",
2069# else
2070 (char_u *)"sh",
2071# endif
2072# endif
2073# endif
2074# endif
2075# endif
2076#endif /* VMS */
2077 (char_u *)0L}},
2078 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2079 (char_u *)&p_shcf, PV_NONE,
2080 {
2081#if defined(MSDOS) || defined(MSWIN)
2082 (char_u *)"/c",
2083#else
2084# if defined(OS2)
2085 (char_u *)"/c",
2086# else
2087 (char_u *)"-c",
2088# endif
2089#endif
2090 (char_u *)0L}},
2091 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2092#ifdef FEAT_QUICKFIX
2093 (char_u *)&p_sp, PV_NONE,
2094 {
2095#if defined(UNIX) || defined(OS2)
2096# ifdef ARCHIE
2097 (char_u *)"2>",
2098# else
2099 (char_u *)"| tee",
2100# endif
2101#else
2102 (char_u *)">",
2103#endif
2104 (char_u *)0L}
2105#else
2106 (char_u *)NULL, PV_NONE,
2107 {(char_u *)0L, (char_u *)0L}
2108#endif
2109 },
2110 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2111 (char_u *)&p_shq, PV_NONE,
2112 {(char_u *)"", (char_u *)0L}},
2113 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2114 (char_u *)&p_srr, PV_NONE,
2115 {(char_u *)">", (char_u *)0L}},
2116 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2117#ifdef BACKSLASH_IN_FILENAME
2118 (char_u *)&p_ssl, PV_NONE,
2119#else
2120 (char_u *)NULL, PV_NONE,
2121#endif
2122 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002123 {"shelltemp", "stmp", P_BOOL,
2124 (char_u *)&p_stmp, PV_NONE,
2125 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"shelltype", "st", P_NUM|P_VI_DEF,
2127#ifdef AMIGA
2128 (char_u *)&p_st, PV_NONE,
2129#else
2130 (char_u *)NULL, PV_NONE,
2131#endif
2132 {(char_u *)0L, (char_u *)0L}},
2133 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2134 (char_u *)&p_sxq, PV_NONE,
2135 {
2136#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2137 (char_u *)"\"",
2138#else
2139 (char_u *)"",
2140#endif
2141 (char_u *)0L}},
2142 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2143 (char_u *)&p_sr, PV_NONE,
2144 {(char_u *)FALSE, (char_u *)0L}},
2145 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2146 (char_u *)&p_sw, PV_SW,
2147 {(char_u *)8L, (char_u *)0L}},
2148 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2149 (char_u *)&p_shm, PV_NONE,
2150 {(char_u *)"", (char_u *)"filnxtToO"}},
2151 {"shortname", "sn", P_BOOL|P_VI_DEF,
2152#ifdef SHORT_FNAME
2153 (char_u *)NULL, PV_NONE,
2154#else
2155 (char_u *)&p_sn, PV_SN,
2156#endif
2157 {(char_u *)FALSE, (char_u *)0L}},
2158 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2159#ifdef FEAT_LINEBREAK
2160 (char_u *)&p_sbr, PV_NONE,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
2164 {(char_u *)"", (char_u *)0L}},
2165 {"showcmd", "sc", P_BOOL|P_VIM,
2166#ifdef FEAT_CMDL_INFO
2167 (char_u *)&p_sc, PV_NONE,
2168#else
2169 (char_u *)NULL, PV_NONE,
2170#endif
2171 {(char_u *)FALSE,
2172#ifdef UNIX
2173 (char_u *)FALSE
2174#else
2175 (char_u *)TRUE
2176#endif
2177 }},
2178 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2179 (char_u *)&p_sft, PV_NONE,
2180 {(char_u *)FALSE, (char_u *)0L}},
2181 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2182 (char_u *)&p_sm, PV_NONE,
2183 {(char_u *)FALSE, (char_u *)0L}},
2184 {"showmode", "smd", P_BOOL|P_VIM,
2185 (char_u *)&p_smd, PV_NONE,
2186 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002187 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2188#ifdef FEAT_WINDOWS
2189 (char_u *)&p_stal, PV_NONE,
2190#else
2191 (char_u *)NULL, PV_NONE,
2192#endif
2193 {(char_u *)1L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2195 (char_u *)&p_ss, PV_NONE,
2196 {(char_u *)0L, (char_u *)0L}},
2197 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2198 (char_u *)&p_siso, PV_NONE,
2199 {(char_u *)0L, (char_u *)0L}},
2200 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)FALSE, (char_u *)0L}},
2203 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2204 (char_u *)&p_scs, PV_NONE,
2205 {(char_u *)FALSE, (char_u *)0L}},
2206 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2207#ifdef FEAT_SMARTINDENT
2208 (char_u *)&p_si, PV_SI,
2209#else
2210 (char_u *)NULL, PV_NONE,
2211#endif
2212 {(char_u *)FALSE, (char_u *)0L}},
2213 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2214 (char_u *)&p_sta, PV_NONE,
2215 {(char_u *)FALSE, (char_u *)0L}},
2216 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2217 (char_u *)&p_sts, PV_STS,
2218 {(char_u *)0L, (char_u *)0L}},
2219 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2220 (char_u *)NULL, PV_NONE,
2221 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002222 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002223#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002224 (char_u *)VAR_WIN, PV_SPELL,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
2228 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002229 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002230#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002231 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002232 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)0L, (char_u *)0L}
2236#endif
2237 },
2238 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002239#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002240 (char_u *)&p_spf, PV_SPF,
2241 {(char_u *)"", (char_u *)0L}
2242#else
2243 (char_u *)NULL, PV_NONE,
2244 {(char_u *)0L, (char_u *)0L}
2245#endif
2246 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002247 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002248#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002249 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002250 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002251#else
2252 (char_u *)NULL, PV_NONE,
2253 {(char_u *)0L, (char_u *)0L}
2254#endif
2255 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002256 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002257#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002258 (char_u *)&p_sps, PV_NONE,
2259 {(char_u *)"best", (char_u *)0L}
2260#else
2261 (char_u *)NULL, PV_NONE,
2262 {(char_u *)0L, (char_u *)0L}
2263#endif
2264 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2266#ifdef FEAT_WINDOWS
2267 (char_u *)&p_sb, PV_NONE,
2268#else
2269 (char_u *)NULL, PV_NONE,
2270#endif
2271 {(char_u *)FALSE, (char_u *)0L}},
2272 {"splitright", "spr", P_BOOL|P_VI_DEF,
2273#ifdef FEAT_VERTSPLIT
2274 (char_u *)&p_spr, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
2278 {(char_u *)FALSE, (char_u *)0L}},
2279 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2280 (char_u *)&p_sol, PV_NONE,
2281 {(char_u *)TRUE, (char_u *)0L}},
2282 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2283#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002284 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
2288 {(char_u *)"", (char_u *)0L}},
2289 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2290 (char_u *)&p_su, PV_NONE,
2291 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2292 (char_u *)0L}},
2293 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002294#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 (char_u *)&p_sua, PV_SUA,
2296 {(char_u *)"", (char_u *)0L}
2297#else
2298 (char_u *)NULL, PV_NONE,
2299 {(char_u *)0L, (char_u *)0L}
2300#endif
2301 },
2302 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2303 (char_u *)&p_swf, PV_SWF,
2304 {(char_u *)TRUE, (char_u *)0L}},
2305 {"swapsync", "sws", P_STRING|P_VI_DEF,
2306 (char_u *)&p_sws, PV_NONE,
2307 {(char_u *)"fsync", (char_u *)0L}},
2308 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2309 (char_u *)&p_swb, PV_NONE,
2310 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002311 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2312#ifdef FEAT_SYN_HL
2313 (char_u *)&p_smc, PV_SMC,
2314 {(char_u *)3000L, (char_u *)0L}
2315#else
2316 (char_u *)NULL, PV_NONE,
2317 {(char_u *)0L, (char_u *)0L}
2318#endif
2319 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002320 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321#ifdef FEAT_SYN_HL
2322 (char_u *)&p_syn, PV_SYN,
2323 {(char_u *)"", (char_u *)0L}
2324#else
2325 (char_u *)NULL, PV_NONE,
2326 {(char_u *)0L, (char_u *)0L}
2327#endif
2328 },
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002329 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2330#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002331 (char_u *)&p_tal, PV_NONE,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002335 {(char_u *)"", (char_u *)0L}},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002336 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2337#ifdef FEAT_WINDOWS
2338 (char_u *)&p_tpm, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
2342 {(char_u *)10L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2344 (char_u *)&p_ts, PV_TS,
2345 {(char_u *)8L, (char_u *)0L}},
2346 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2347 (char_u *)&p_tbs, PV_NONE,
2348#ifdef VMS /* binary searching doesn't appear to work on VMS */
2349 {(char_u *)0L, (char_u *)0L}
2350#else
2351 {(char_u *)TRUE, (char_u *)0L}
2352#endif
2353 },
2354 {"taglength", "tl", P_NUM|P_VI_DEF,
2355 (char_u *)&p_tl, PV_NONE,
2356 {(char_u *)0L, (char_u *)0L}},
2357 {"tagrelative", "tr", P_BOOL|P_VIM,
2358 (char_u *)&p_tr, PV_NONE,
2359 {(char_u *)FALSE, (char_u *)TRUE}},
2360 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002361 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {
2363#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2364 (char_u *)"./tags,./TAGS,tags,TAGS",
2365#else
2366 (char_u *)"./tags,tags",
2367#endif
2368 (char_u *)0L}},
2369 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2370 (char_u *)&p_tgst, PV_NONE,
2371 {(char_u *)TRUE, (char_u *)0L}},
2372 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2373 (char_u *)&T_NAME, PV_NONE,
2374 {(char_u *)"", (char_u *)0L}},
2375 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2376#ifdef FEAT_ARABIC
2377 (char_u *)&p_tbidi, PV_NONE,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
2381 {(char_u *)FALSE, (char_u *)0L}},
2382 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2383#ifdef FEAT_MBYTE
2384 (char_u *)&p_tenc, PV_NONE,
2385 {(char_u *)"", (char_u *)0L}
2386#else
2387 (char_u *)NULL, PV_NONE,
2388 {(char_u *)0L, (char_u *)0L}
2389#endif
2390 },
2391 {"terse", NULL, P_BOOL|P_VI_DEF,
2392 (char_u *)&p_terse, PV_NONE,
2393 {(char_u *)FALSE, (char_u *)0L}},
2394 {"textauto", "ta", P_BOOL|P_VIM,
2395 (char_u *)&p_ta, PV_NONE,
2396 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2397 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2398 (char_u *)&p_tx, PV_TX,
2399 {
2400#ifdef USE_CRNL
2401 (char_u *)TRUE,
2402#else
2403 (char_u *)FALSE,
2404#endif
2405 (char_u *)0L}},
2406 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2407 (char_u *)&p_tw, PV_TW,
2408 {(char_u *)0L, (char_u *)0L}},
2409 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2410#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002411 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412#else
2413 (char_u *)NULL, PV_NONE,
2414#endif
2415 {(char_u *)"", (char_u *)0L}},
2416 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2417 (char_u *)&p_to, PV_NONE,
2418 {(char_u *)FALSE, (char_u *)0L}},
2419 {"timeout", "to", P_BOOL|P_VI_DEF,
2420 (char_u *)&p_timeout, PV_NONE,
2421 {(char_u *)TRUE, (char_u *)0L}},
2422 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2423 (char_u *)&p_tm, PV_NONE,
2424 {(char_u *)1000L, (char_u *)0L}},
2425 {"title", NULL, P_BOOL|P_VI_DEF,
2426#ifdef FEAT_TITLE
2427 (char_u *)&p_title, PV_NONE,
2428#else
2429 (char_u *)NULL, PV_NONE,
2430#endif
2431 {(char_u *)FALSE, (char_u *)0L}},
2432 {"titlelen", NULL, P_NUM|P_VI_DEF,
2433#ifdef FEAT_TITLE
2434 (char_u *)&p_titlelen, PV_NONE,
2435#else
2436 (char_u *)NULL, PV_NONE,
2437#endif
2438 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002439 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440#ifdef FEAT_TITLE
2441 (char_u *)&p_titleold, PV_NONE,
2442 {(char_u *)N_("Thanks for flying Vim"),
2443 (char_u *)0L}
2444#else
2445 (char_u *)NULL, PV_NONE,
2446 {(char_u *)0L, (char_u *)0L}
2447#endif
2448 },
2449 {"titlestring", NULL, P_STRING|P_VI_DEF,
2450#ifdef FEAT_TITLE
2451 (char_u *)&p_titlestring, PV_NONE,
2452#else
2453 (char_u *)NULL, PV_NONE,
2454#endif
2455 {(char_u *)"", (char_u *)0L}},
2456#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2457 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2458 (char_u *)&p_toolbar, PV_NONE,
2459 {(char_u *)"icons,tooltips", (char_u *)0L}},
2460#endif
2461#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2462 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2463 (char_u *)&p_tbis, PV_NONE,
2464 {(char_u *)"small", (char_u *)0L}},
2465#endif
2466 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2467 (char_u *)&p_ttimeout, PV_NONE,
2468 {(char_u *)FALSE, (char_u *)0L}},
2469 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2470 (char_u *)&p_ttm, PV_NONE,
2471 {(char_u *)-1L, (char_u *)0L}},
2472 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2473 (char_u *)&p_tbi, PV_NONE,
2474 {(char_u *)TRUE, (char_u *)0L}},
2475 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2476 (char_u *)&p_tf, PV_NONE,
2477 {(char_u *)FALSE, (char_u *)0L}},
2478 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2479#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2480 (char_u *)&p_ttym, PV_NONE,
2481#else
2482 (char_u *)NULL, PV_NONE,
2483#endif
2484 {(char_u *)"", (char_u *)0L}},
2485 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2486 (char_u *)&p_ttyscroll, PV_NONE,
2487 {(char_u *)999L, (char_u *)0L}},
2488 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2489 (char_u *)&T_NAME, PV_NONE,
2490 {(char_u *)"", (char_u *)0L}},
2491 {"undolevels", "ul", P_NUM|P_VI_DEF,
2492 (char_u *)&p_ul, PV_NONE,
2493 {
2494#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2495 (char_u *)1000L,
2496#else
2497 (char_u *)100L,
2498#endif
2499 (char_u *)0L}},
2500 {"updatecount", "uc", P_NUM|P_VI_DEF,
2501 (char_u *)&p_uc, PV_NONE,
2502 {(char_u *)200L, (char_u *)0L}},
2503 {"updatetime", "ut", P_NUM|P_VI_DEF,
2504 (char_u *)&p_ut, PV_NONE,
2505 {(char_u *)4000L, (char_u *)0L}},
2506 {"verbose", "vbs", P_NUM|P_VI_DEF,
2507 (char_u *)&p_verbose, PV_NONE,
2508 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002509 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2510 (char_u *)&p_vfile, PV_NONE,
2511 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2513#ifdef FEAT_SESSION
2514 (char_u *)&p_vdir, PV_NONE,
2515 {(char_u *)DFLT_VDIR, (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
2520 },
2521 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2522#ifdef FEAT_SESSION
2523 (char_u *)&p_vop, PV_NONE,
2524 {(char_u *)"folds,options,cursor", (char_u *)0L}
2525#else
2526 (char_u *)NULL, PV_NONE,
2527 {(char_u *)0L, (char_u *)0L}
2528#endif
2529 },
2530 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2531#ifdef FEAT_VIMINFO
2532 (char_u *)&p_viminfo, PV_NONE,
2533#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2534 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2535#else
2536# ifdef AMIGA
2537 {(char_u *)"",
2538 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2539# else
2540 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2541# endif
2542#endif
2543#else
2544 (char_u *)NULL, PV_NONE,
2545 {(char_u *)0L, (char_u *)0L}
2546#endif
2547 },
2548 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2549#ifdef FEAT_VIRTUALEDIT
2550 (char_u *)&p_ve, PV_NONE,
2551 {(char_u *)"", (char_u *)""}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
2556 },
2557 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2558 (char_u *)&p_vb, PV_NONE,
2559 {(char_u *)FALSE, (char_u *)0L}},
2560 {"w300", NULL, P_NUM|P_VI_DEF,
2561 (char_u *)NULL, PV_NONE,
2562 {(char_u *)0L, (char_u *)0L}},
2563 {"w1200", NULL, P_NUM|P_VI_DEF,
2564 (char_u *)NULL, PV_NONE,
2565 {(char_u *)0L, (char_u *)0L}},
2566 {"w9600", NULL, P_NUM|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
2568 {(char_u *)0L, (char_u *)0L}},
2569 {"warn", NULL, P_BOOL|P_VI_DEF,
2570 (char_u *)&p_warn, PV_NONE,
2571 {(char_u *)TRUE, (char_u *)0L}},
2572 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2573 (char_u *)&p_wiv, PV_NONE,
2574 {(char_u *)FALSE, (char_u *)0L}},
2575 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2576 (char_u *)&p_ww, PV_NONE,
2577 {(char_u *)"", (char_u *)"b,s"}},
2578 {"wildchar", "wc", P_NUM|P_VIM,
2579 (char_u *)&p_wc, PV_NONE,
2580 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2581 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2582 (char_u *)&p_wcm, PV_NONE,
2583 {(char_u *)0L, (char_u *)0L}},
2584 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2585#ifdef FEAT_WILDIGN
2586 (char_u *)&p_wig, PV_NONE,
2587#else
2588 (char_u *)NULL, PV_NONE,
2589#endif
2590 {(char_u *)"", (char_u *)0L}},
2591 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2592#ifdef FEAT_WILDMENU
2593 (char_u *)&p_wmnu, PV_NONE,
2594#else
2595 (char_u *)NULL, PV_NONE,
2596#endif
2597 {(char_u *)FALSE, (char_u *)0L}},
2598 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2599 (char_u *)&p_wim, PV_NONE,
2600 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002601 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2602#ifdef FEAT_CMDL_COMPL
2603 (char_u *)&p_wop, PV_NONE,
2604 {(char_u *)"", (char_u *)0L}
2605#else
2606 (char_u *)NULL, PV_NONE,
2607 {(char_u *)NULL, (char_u *)0L}
2608#endif
2609 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2611#ifdef FEAT_WAK
2612 (char_u *)&p_wak, PV_NONE,
2613 {(char_u *)"menu", (char_u *)0L}
2614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)NULL, (char_u *)0L}
2617#endif
2618 },
2619 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002620 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {(char_u *)0L, (char_u *)0L}},
2622 {"winheight", "wh", P_NUM|P_VI_DEF,
2623#ifdef FEAT_WINDOWS
2624 (char_u *)&p_wh, PV_NONE,
2625#else
2626 (char_u *)NULL, PV_NONE,
2627#endif
2628 {(char_u *)1L, (char_u *)0L}},
2629 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002630#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 (char_u *)VAR_WIN, PV_WFH,
2632#else
2633 (char_u *)NULL, PV_NONE,
2634#endif
2635 {(char_u *)FALSE, (char_u *)0L}},
2636 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2637#ifdef FEAT_WINDOWS
2638 (char_u *)&p_wmh, PV_NONE,
2639#else
2640 (char_u *)NULL, PV_NONE,
2641#endif
2642 {(char_u *)1L, (char_u *)0L}},
2643 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2644#ifdef FEAT_VERTSPLIT
2645 (char_u *)&p_wmw, PV_NONE,
2646#else
2647 (char_u *)NULL, PV_NONE,
2648#endif
2649 {(char_u *)1L, (char_u *)0L}},
2650 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2651#ifdef FEAT_VERTSPLIT
2652 (char_u *)&p_wiw, PV_NONE,
2653#else
2654 (char_u *)NULL, PV_NONE,
2655#endif
2656 {(char_u *)20L, (char_u *)0L}},
2657 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2658 (char_u *)VAR_WIN, PV_WRAP,
2659 {(char_u *)TRUE, (char_u *)0L}},
2660 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2661 (char_u *)&p_wm, PV_WM,
2662 {(char_u *)0L, (char_u *)0L}},
2663 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2664 (char_u *)&p_ws, PV_NONE,
2665 {(char_u *)TRUE, (char_u *)0L}},
2666 {"write", NULL, P_BOOL|P_VI_DEF,
2667 (char_u *)&p_write, PV_NONE,
2668 {(char_u *)TRUE, (char_u *)0L}},
2669 {"writeany", "wa", P_BOOL|P_VI_DEF,
2670 (char_u *)&p_wa, PV_NONE,
2671 {(char_u *)FALSE, (char_u *)0L}},
2672 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2673 (char_u *)&p_wb, PV_NONE,
2674 {
2675#ifdef FEAT_WRITEBACKUP
2676 (char_u *)TRUE,
2677#else
2678 (char_u *)FALSE,
2679#endif
2680 (char_u *)0L}},
2681 {"writedelay", "wd", P_NUM|P_VI_DEF,
2682 (char_u *)&p_wd, PV_NONE,
2683 {(char_u *)0L, (char_u *)0L}},
2684
2685/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002686#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 (char_u *)&vvv, PV_NONE, \
2688 {(char_u *)"", (char_u *)0L}},
2689
2690 p_term("t_AB", T_CAB)
2691 p_term("t_AF", T_CAF)
2692 p_term("t_AL", T_CAL)
2693 p_term("t_al", T_AL)
2694 p_term("t_bc", T_BC)
2695 p_term("t_cd", T_CD)
2696 p_term("t_ce", T_CE)
2697 p_term("t_cl", T_CL)
2698 p_term("t_cm", T_CM)
2699 p_term("t_Co", T_CCO)
2700 p_term("t_CS", T_CCS)
2701 p_term("t_cs", T_CS)
2702#ifdef FEAT_VERTSPLIT
2703 p_term("t_CV", T_CSV)
2704#endif
2705 p_term("t_ut", T_UT)
2706 p_term("t_da", T_DA)
2707 p_term("t_db", T_DB)
2708 p_term("t_DL", T_CDL)
2709 p_term("t_dl", T_DL)
2710 p_term("t_fs", T_FS)
2711 p_term("t_IE", T_CIE)
2712 p_term("t_IS", T_CIS)
2713 p_term("t_ke", T_KE)
2714 p_term("t_ks", T_KS)
2715 p_term("t_le", T_LE)
2716 p_term("t_mb", T_MB)
2717 p_term("t_md", T_MD)
2718 p_term("t_me", T_ME)
2719 p_term("t_mr", T_MR)
2720 p_term("t_ms", T_MS)
2721 p_term("t_nd", T_ND)
2722 p_term("t_op", T_OP)
2723 p_term("t_RI", T_CRI)
2724 p_term("t_RV", T_CRV)
2725 p_term("t_Sb", T_CSB)
2726 p_term("t_Sf", T_CSF)
2727 p_term("t_se", T_SE)
2728 p_term("t_so", T_SO)
2729 p_term("t_sr", T_SR)
2730 p_term("t_ts", T_TS)
2731 p_term("t_te", T_TE)
2732 p_term("t_ti", T_TI)
2733 p_term("t_ue", T_UE)
2734 p_term("t_us", T_US)
2735 p_term("t_vb", T_VB)
2736 p_term("t_ve", T_VE)
2737 p_term("t_vi", T_VI)
2738 p_term("t_vs", T_VS)
2739 p_term("t_WP", T_CWP)
2740 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002741 p_term("t_SI", T_CSI)
2742 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 p_term("t_xs", T_XS)
2744 p_term("t_ZH", T_CZH)
2745 p_term("t_ZR", T_CZR)
2746
2747/* terminal key codes are not in here */
2748
2749 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2750};
2751
2752#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2753
2754#ifdef FEAT_MBYTE
2755static char *(p_ambw_values[]) = {"single", "double", NULL};
2756#endif
2757static char *(p_bg_values[]) = {"light", "dark", NULL};
2758static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2759static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002760#ifdef FEAT_CMDL_COMPL
2761static char *(p_wop_values[]) = {"tagfile", NULL};
2762#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763#ifdef FEAT_WAK
2764static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2765#endif
2766static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2767#ifdef FEAT_VISUAL
2768static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2769static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2770#endif
2771#ifdef FEAT_VISUAL
2772static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2773#endif
2774#ifdef FEAT_BROWSE
2775static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2776#endif
2777#ifdef FEAT_SCROLLBIND
2778static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2779#endif
2780static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002781static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782#ifdef FEAT_VERTSPLIT
2783static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2784#endif
2785#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002786# ifdef FEAT_AUTOCMD
2787static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2788# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002790# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2792#endif
2793static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2794#ifdef FEAT_FOLDING
2795static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002796# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002798# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 NULL};
2800static char *(p_fcl_values[]) = {"all", NULL};
2801#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002802#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002803static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002804#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805
2806static void set_option_default __ARGS((int, int opt_flags, int compatible));
2807static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002808static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002809static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810static char_u *illegal_char __ARGS((char_u *, int));
2811static int string_to_key __ARGS((char_u *arg));
2812#ifdef FEAT_CMDWIN
2813static char_u *check_cedit __ARGS((void));
2814#endif
2815#ifdef FEAT_TITLE
2816static void did_set_title __ARGS((int icon));
2817#endif
2818static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2819static void didset_options __ARGS((void));
2820static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002821#if defined(FEAT_EVAL) || defined(PROTO)
2822static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2823#else
2824# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2825#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2827static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2828static 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));
2829static char_u *set_chars_option __ARGS((char_u **varp));
2830#ifdef FEAT_CLIPBOARD
2831static char_u *check_clipboard_option __ARGS((void));
2832#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002833#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002834static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002835#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002836#ifdef FEAT_EVAL
2837static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002840static 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 +00002841static void check_redraw __ARGS((long_u flags));
2842static int findoption __ARGS((char_u *));
2843static int find_key_option __ARGS((char_u *));
2844static void showoptions __ARGS((int all, int opt_flags));
2845static int optval_default __ARGS((struct vimoption *, char_u *varp));
2846static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2847static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2848static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2849static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2850static int istermoption __ARGS((struct vimoption *));
2851static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2852static char_u *get_varp __ARGS((struct vimoption *));
2853static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2854static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2855#ifdef FEAT_LANGMAP
2856static void langmap_init __ARGS((void));
2857static void langmap_set __ARGS((void));
2858#endif
2859static void paste_option_changed __ARGS((void));
2860static void compatible_set __ARGS((void));
2861#ifdef FEAT_LINEBREAK
2862static void fill_breakat_flags __ARGS((void));
2863#endif
2864static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2865static int check_opt_strings __ARGS((char_u *val, char **values, int));
2866static int check_opt_wim __ARGS((void));
2867
2868/*
2869 * Initialize the options, first part.
2870 *
2871 * Called only once from main(), just after creating the first buffer.
2872 */
2873 void
2874set_init_1()
2875{
2876 char_u *p;
2877 int opt_idx;
2878 long n;
2879
2880#ifdef FEAT_LANGMAP
2881 langmap_init();
2882#endif
2883
2884 /* Be Vi compatible by default */
2885 p_cp = TRUE;
2886
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002887 /* Use POSIX compatibility when $VIM_POSIX is set. */
2888 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002889 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002890 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002891 set_string_default("shm", (char_u *)"A");
2892 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002893
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 /*
2895 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002896 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002898 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2900# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002901 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002903 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002905 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906# endif
2907#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002908 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 set_string_default("sh", p);
2910
2911#ifdef FEAT_WILDIGN
2912 /*
2913 * Set the default for 'backupskip' to include environment variables for
2914 * temp files.
2915 */
2916 {
2917# ifdef UNIX
2918 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2919# else
2920 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2921# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002922 int len;
2923 garray_T ga;
2924 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925
2926 ga_init2(&ga, 1, 100);
2927 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2928 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002929 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930# ifdef UNIX
2931 if (*names[n] == NUL)
2932 p = (char_u *)"/tmp";
2933 else
2934# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002935 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 if (p != NULL && *p != NUL)
2937 {
2938 /* First time count the NUL, otherwise count the ','. */
2939 len = STRLEN(p) + 3;
2940 if (ga_grow(&ga, len) == OK)
2941 {
2942 if (ga.ga_len > 0)
2943 STRCAT(ga.ga_data, ",");
2944 STRCAT(ga.ga_data, p);
2945 add_pathsep(ga.ga_data);
2946 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 ga.ga_len += len;
2948 }
2949 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002950 if (mustfree)
2951 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 }
2953 if (ga.ga_data != NULL)
2954 {
2955 set_string_default("bsk", ga.ga_data);
2956 vim_free(ga.ga_data);
2957 }
2958 }
2959#endif
2960
2961 /*
2962 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2963 */
2964 opt_idx = findoption((char_u *)"maxmemtot");
2965#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2966 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2967#endif
2968 {
2969#ifdef HAVE_AVAIL_MEM
2970 /* Use amount of memory available at this moment. */
2971 n = (mch_avail_mem(FALSE) >> 11);
2972#else
2973# ifdef HAVE_TOTAL_MEM
2974 /* Use amount of memory available to Vim. */
2975 n = (mch_total_mem(FALSE) >> 11);
2976# else
2977 n = (0x7fffffff >> 11);
2978# endif
2979#endif
2980 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2981 opt_idx = findoption((char_u *)"maxmem");
2982#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2983 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2984 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2985#endif
2986 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2987 }
2988
2989#ifdef FEAT_GUI_W32
2990 /* force 'shortname' for Win32s */
2991 if (gui_is_win32s())
2992 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2993 (char_u *)TRUE;
2994#endif
2995
2996#ifdef FEAT_SEARCHPATH
2997 {
2998 char_u *cdpath;
2999 char_u *buf;
3000 int i;
3001 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003002 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003
3004 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003005 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 if (cdpath != NULL)
3007 {
3008 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3009 if (buf != NULL)
3010 {
3011 buf[0] = ','; /* start with ",", current dir first */
3012 j = 1;
3013 for (i = 0; cdpath[i] != NUL; ++i)
3014 {
3015 if (vim_ispathlistsep(cdpath[i]))
3016 buf[j++] = ',';
3017 else
3018 {
3019 if (cdpath[i] == ' ' || cdpath[i] == ',')
3020 buf[j++] = '\\';
3021 buf[j++] = cdpath[i];
3022 }
3023 }
3024 buf[j] = NUL;
3025 opt_idx = findoption((char_u *)"cdpath");
3026 options[opt_idx].def_val[VI_DEFAULT] = buf;
3027 options[opt_idx].flags |= P_DEF_ALLOCED;
3028 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003029 if (mustfree)
3030 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 }
3032 }
3033#endif
3034
3035#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3036 /* Set print encoding on platforms that don't default to latin1 */
3037 set_string_default("penc",
3038# if defined(MSWIN) || defined(OS2)
3039 (char_u *)"cp1252"
3040# else
3041# ifdef VMS
3042 (char_u *)"dec-mcs"
3043# else
3044# ifdef EBCDIC
3045 (char_u *)"ebcdic-uk"
3046# else
3047# ifdef MAC
3048 (char_u *)"mac-roman"
3049# else /* HPUX */
3050 (char_u *)"hp-roman8"
3051# endif
3052# endif
3053# endif
3054# endif
3055 );
3056#endif
3057
3058#ifdef FEAT_POSTSCRIPT
3059 /* 'printexpr' must be allocated to be able to evaluate it. */
3060 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003061# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3062 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063# else
3064# ifdef VMS
3065 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3066
3067# else
3068 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3069# endif
3070# endif
3071 );
3072#endif
3073
3074 /*
3075 * Set all the options (except the terminal options) to their default
3076 * value. Also set the global value for local options.
3077 */
3078 set_options_default(0);
3079
3080#ifdef FEAT_GUI
3081 if (found_reverse_arg)
3082 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3083#endif
3084
3085 curbuf->b_p_initialized = TRUE;
3086 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3087 check_buf_options(curbuf);
3088 check_win_options(curwin);
3089 check_options();
3090
3091 /* Must be before option_expand(), because that one needs vim_isIDc() */
3092 didset_options();
3093
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003094#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003095 /* Use the current chartab for the generic chartab. */
3096 init_spell_chartab();
3097#endif
3098
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099#ifdef FEAT_LINEBREAK
3100 /*
3101 * initialize the table for 'breakat'.
3102 */
3103 fill_breakat_flags();
3104#endif
3105
3106 /*
3107 * Expand environment variables and things like "~" for the defaults.
3108 * If option_expand() returns non-NULL the variable is expanded. This can
3109 * only happen for non-indirect options.
3110 * Also set the default to the expanded value, so ":set" does not list
3111 * them.
3112 * Don't set the P_ALLOCED flag, because we don't want to free the
3113 * default.
3114 */
3115 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3116 {
3117 if ((options[opt_idx].flags & P_GETTEXT)
3118 && options[opt_idx].var != NULL)
3119 p = (char_u *)_(*(char **)options[opt_idx].var);
3120 else
3121 p = option_expand(opt_idx, NULL);
3122 if (p != NULL && (p = vim_strsave(p)) != NULL)
3123 {
3124 *(char_u **)options[opt_idx].var = p;
3125 /* VIMEXP
3126 * Defaults for all expanded options are currently the same for Vi
3127 * and Vim. When this changes, add some code here! Also need to
3128 * split P_DEF_ALLOCED in two.
3129 */
3130 if (options[opt_idx].flags & P_DEF_ALLOCED)
3131 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3132 options[opt_idx].def_val[VI_DEFAULT] = p;
3133 options[opt_idx].flags |= P_DEF_ALLOCED;
3134 }
3135 }
3136
3137 /* Initialize the highlight_attr[] table. */
3138 highlight_changed();
3139
3140 save_file_ff(curbuf); /* Buffer is unchanged */
3141
3142 /* Parse default for 'wildmode' */
3143 check_opt_wim();
3144
3145#if defined(FEAT_ARABIC)
3146 /* Detect use of mlterm.
3147 * Mlterm is a terminal emulator akin to xterm that has some special
3148 * abilities (bidi namely).
3149 * NOTE: mlterm's author is being asked to 'set' a variable
3150 * instead of an environment variable due to inheritance.
3151 */
3152 if (mch_getenv((char_u *)"MLTERM") != NULL)
3153 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3154#endif
3155
3156#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3157 /* Parse default for 'fillchars'. */
3158 (void)set_chars_option(&p_fcs);
3159#endif
3160
3161#ifdef FEAT_CLIPBOARD
3162 /* Parse default for 'clipboard' */
3163 (void)check_clipboard_option();
3164#endif
3165
3166#ifdef FEAT_MBYTE
3167# if defined(WIN3264) && defined(FEAT_GETTEXT)
3168 /*
3169 * If $LANG isn't set, try to get a good value for it. This makes the
3170 * right language be used automatically. Don't do this for English.
3171 */
3172 if (mch_getenv((char_u *)"LANG") == NULL)
3173 {
3174 char buf[20];
3175
3176 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3177 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3178 * only the first two. */
3179 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3180 (LPTSTR)buf, 20);
3181 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3182 {
3183 /* There are a few exceptions (probably more) */
3184 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3185 STRCPY(buf, "zh_TW");
3186 else if (STRNICMP(buf, "chs", 3) == 0
3187 || STRNICMP(buf, "zhc", 3) == 0)
3188 STRCPY(buf, "zh_CN");
3189 else if (STRNICMP(buf, "jp", 2) == 0)
3190 STRCPY(buf, "ja");
3191 else
3192 buf[2] = NUL; /* truncate to two-letter code */
3193 vim_setenv("LANG", buf);
3194 }
3195 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003196# else
3197# ifdef MACOS
3198 if (mch_getenv((char_u *)"LANG") == NULL)
3199 {
3200 char buf[20];
3201 if (LocaleRefGetPartString(NULL,
3202 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3203 kLocaleRegionMask | kLocaleRegionVariantMask,
3204 sizeof buf, buf) == noErr && *buf)
3205 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003206 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003207# ifdef HAVE_LOCALE_H
3208 setlocale(LC_ALL, "");
3209# endif
3210 }
3211 }
3212# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213# endif
3214
3215 /* enc_locale() will try to find the encoding of the current locale. */
3216 p = enc_locale();
3217 if (p != NULL)
3218 {
3219 char_u *save_enc;
3220
3221 /* Try setting 'encoding' and check if the value is valid.
3222 * If not, go back to the default "latin1". */
3223 save_enc = p_enc;
3224 p_enc = p;
3225 if (mb_init() == NULL)
3226 {
3227 opt_idx = findoption((char_u *)"encoding");
3228 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3229 options[opt_idx].flags |= P_DEF_ALLOCED;
3230
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003231#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3232 || defined(VMS)
3233 if (STRCMP(p_enc, "latin1") == 0
3234# ifdef FEAT_MBYTE
3235 || enc_utf8
3236# endif
3237 )
3238 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003239 /* Adjust the default for 'isprint' and 'iskeyword' to match
3240 * latin1. Also set the defaults for when 'nocompatible' is
3241 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003242 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003243 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003244 set_string_option_direct((char_u *)"isk", -1,
3245 ISK_LATIN1, OPT_FREE, SID_NONE);
3246 opt_idx = findoption((char_u *)"isp");
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003247 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003248 opt_idx = findoption((char_u *)"isk");
3249 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003250 (void)init_chartab();
3251 }
3252#endif
3253
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254# if defined(WIN3264) && !defined(FEAT_GUI)
3255 /* Win32 console: When GetACP() returns a different value from
3256 * GetConsoleCP() set 'termencoding'. */
3257 if (GetACP() != GetConsoleCP())
3258 {
3259 char buf[50];
3260
3261 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3262 p_tenc = vim_strsave((char_u *)buf);
3263 if (p_tenc != NULL)
3264 {
3265 opt_idx = findoption((char_u *)"termencoding");
3266 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3267 options[opt_idx].flags |= P_DEF_ALLOCED;
3268 convert_setup(&input_conv, p_tenc, p_enc);
3269 convert_setup(&output_conv, p_enc, p_tenc);
3270 }
3271 else
3272 p_tenc = empty_option;
3273 }
3274# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003275# if defined(WIN3264) && defined(FEAT_MBYTE)
3276 /* $HOME may have characters in active code page. */
3277 init_homedir();
3278# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279 }
3280 else
3281 {
3282 vim_free(p_enc);
3283 p_enc = save_enc;
3284 }
3285 }
3286#endif
3287
3288#ifdef FEAT_MULTI_LANG
3289 /* Set the default for 'helplang'. */
3290 set_helplang_default(get_mess_lang());
3291#endif
3292}
3293
3294/*
3295 * Set an option to its default value.
3296 * This does not take care of side effects!
3297 */
3298 static void
3299set_option_default(opt_idx, opt_flags, compatible)
3300 int opt_idx;
3301 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3302 int compatible; /* use Vi default value */
3303{
3304 char_u *varp; /* pointer to variable for current option */
3305 int dvi; /* index in def_val[] */
3306 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003307 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3309
3310 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3311 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003312 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 {
3314 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3315 if (flags & P_STRING)
3316 {
3317 /* Use set_string_option_direct() for local options to handle
3318 * freeing and allocating the value. */
3319 if (options[opt_idx].indir != PV_NONE)
3320 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003321 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 else
3323 {
3324 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3325 free_string_option(*(char_u **)(varp));
3326 *(char_u **)varp = options[opt_idx].def_val[dvi];
3327 options[opt_idx].flags &= ~P_ALLOCED;
3328 }
3329 }
3330 else if (flags & P_NUM)
3331 {
3332 if (varp == (char_u *)PV_SCROLL)
3333 win_comp_scroll(curwin);
3334 else
3335 {
3336 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3337 /* May also set global value for local option. */
3338 if (both)
3339 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3340 *(long *)varp;
3341 }
3342 }
3343 else /* P_BOOL */
3344 {
3345 /* the cast to long is required for Manx C */
3346 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3347 /* May also set global value for local option. */
3348 if (both)
3349 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3350 *(int *)varp;
3351 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003352
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003353 /* The default value is not insecure. */
3354 flagsp = insecure_flag(opt_idx, opt_flags);
3355 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356 }
3357
3358#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003359 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360#endif
3361}
3362
3363/*
3364 * Set all options (except terminal options) to their default value.
3365 */
3366 static void
3367set_options_default(opt_flags)
3368 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3369{
3370 int i;
3371#ifdef FEAT_WINDOWS
3372 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003373 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374#endif
3375
3376 for (i = 0; !istermoption(&options[i]); i++)
3377 if (!(options[i].flags & P_NODEFAULT))
3378 set_option_default(i, opt_flags, p_cp);
3379
3380#ifdef FEAT_WINDOWS
3381 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003382 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 win_comp_scroll(wp);
3384#else
3385 win_comp_scroll(curwin);
3386#endif
3387}
3388
3389/*
3390 * Set the Vi-default value of a string option.
3391 * Used for 'sh', 'backupskip' and 'term'.
3392 */
3393 void
3394set_string_default(name, val)
3395 char *name;
3396 char_u *val;
3397{
3398 char_u *p;
3399 int opt_idx;
3400
3401 p = vim_strsave(val);
3402 if (p != NULL) /* we don't want a NULL */
3403 {
3404 opt_idx = findoption((char_u *)name);
3405 if (options[opt_idx].flags & P_DEF_ALLOCED)
3406 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3407 options[opt_idx].def_val[VI_DEFAULT] = p;
3408 options[opt_idx].flags |= P_DEF_ALLOCED;
3409 }
3410}
3411
3412/*
3413 * Set the Vi-default value of a number option.
3414 * Used for 'lines' and 'columns'.
3415 */
3416 void
3417set_number_default(name, val)
3418 char *name;
3419 long val;
3420{
3421 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3422}
3423
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003424#if defined(EXITFREE) || defined(PROTO)
3425/*
3426 * Free all options.
3427 */
3428 void
3429free_all_options()
3430{
3431 int i;
3432
3433 for (i = 0; !istermoption(&options[i]); i++)
3434 {
3435 if (options[i].indir == PV_NONE)
3436 {
3437 /* global option: free value and default value. */
3438 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3439 free_string_option(*(char_u **)options[i].var);
3440 if (options[i].flags & P_DEF_ALLOCED)
3441 free_string_option(options[i].def_val[VI_DEFAULT]);
3442 }
3443 else if (options[i].var != VAR_WIN
3444 && (options[i].flags & P_STRING))
3445 /* buffer-local option: free global value */
3446 free_string_option(*(char_u **)options[i].var);
3447 }
3448}
3449#endif
3450
3451
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452/*
3453 * Initialize the options, part two: After getting Rows and Columns and
3454 * setting 'term'.
3455 */
3456 void
3457set_init_2()
3458{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003459 int idx;
3460
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 /*
3462 * 'scroll' defaults to half the window height. Note that this default is
3463 * wrong when the window height changes.
3464 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003465 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003466 idx = findoption((char_u *)"scroll");
3467 if (!(options[idx].flags & P_WAS_SET))
3468 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 comp_col();
3470
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003471 /*
3472 * 'window' is only for backwards compatibility with Vi.
3473 * Default is Rows - 1.
3474 */
3475 idx = findoption((char_u *)"wi");
3476 if (!(options[idx].flags & P_WAS_SET))
3477 p_window = Rows - 1;
3478 set_number_default("window", Rows - 1);
3479
Bram Moolenaarf740b292006-02-16 22:11:02 +00003480 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003482 /*
3483 * If 'background' wasn't set by the user, try guessing the value,
3484 * depending on the terminal name. Only need to check for terminals
3485 * with a dark background, that can handle color.
3486 */
3487 idx = findoption((char_u *)"bg");
3488 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003489 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003490 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003491 /* don't mark it as set, when starting the GUI it may be
3492 * changed again */
3493 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494 }
3495#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003496
3497#ifdef CURSOR_SHAPE
3498 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3499#endif
3500#ifdef FEAT_MOUSESHAPE
3501 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3502#endif
3503#ifdef FEAT_PRINTER
3504 (void)parse_printoptions(); /* parse 'printoptions' default value */
3505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506}
3507
3508/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003509 * Return "dark" or "light" depending on the kind of terminal.
3510 * This is just guessing! Recognized are:
3511 * "linux" Linux console
3512 * "screen.linux" Linux console with screen
3513 * "cygwin" Cygwin shell
3514 * "putty" Putty program
3515 * We also check the COLORFGBG environment variable, which is set by
3516 * rxvt and derivatives. This variable contains either two or three
3517 * values separated by semicolons; we want the last value in either
3518 * case. If this value is 0-6 or 8, our background is dark.
3519 */
3520 static char_u *
3521term_bg_default()
3522{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003523#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3524 /* DOS console nearly always black */
3525 return (char_u *)"dark";
3526#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003527 char_u *p;
3528
Bram Moolenaarf740b292006-02-16 22:11:02 +00003529 if (STRCMP(T_NAME, "linux") == 0
3530 || STRCMP(T_NAME, "screen.linux") == 0
3531 || STRCMP(T_NAME, "cygwin") == 0
3532 || STRCMP(T_NAME, "putty") == 0
3533 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3534 && (p = vim_strrchr(p, ';')) != NULL
3535 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3536 && p[2] == NUL))
3537 return (char_u *)"dark";
3538 return (char_u *)"light";
3539#endif
3540}
3541
3542/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003543 * Initialize the options, part three: After reading the .vimrc
3544 */
3545 void
3546set_init_3()
3547{
3548#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3549/*
3550 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3551 * This is done after other initializations, where 'shell' might have been
3552 * set, but only if they have not been set before.
3553 */
3554 char_u *p;
3555 int idx_srr;
3556 int do_srr;
3557#ifdef FEAT_QUICKFIX
3558 int idx_sp;
3559 int do_sp;
3560#endif
3561
3562 idx_srr = findoption((char_u *)"srr");
3563 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3564#ifdef FEAT_QUICKFIX
3565 idx_sp = findoption((char_u *)"sp");
3566 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3567#endif
3568
3569 /*
3570 * Isolate the name of the shell:
3571 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3572 * - Remove any argument. E.g., "csh -f" -> "csh".
3573 */
3574 p = gettail(p_sh);
3575 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3576 if (p != NULL)
3577 {
3578 /*
3579 * Default for p_sp is "| tee", for p_srr is ">".
3580 * For known shells it is changed here to include stderr.
3581 */
3582 if ( fnamecmp(p, "csh") == 0
3583 || fnamecmp(p, "tcsh") == 0
3584# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3585 || fnamecmp(p, "csh.exe") == 0
3586 || fnamecmp(p, "tcsh.exe") == 0
3587# endif
3588 )
3589 {
3590#if defined(FEAT_QUICKFIX)
3591 if (do_sp)
3592 {
3593# ifdef WIN3264
3594 p_sp = (char_u *)">&";
3595# else
3596 p_sp = (char_u *)"|& tee";
3597# endif
3598 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3599 }
3600#endif
3601 if (do_srr)
3602 {
3603 p_srr = (char_u *)">&";
3604 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3605 }
3606 }
3607 else
3608# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3609 if ( fnamecmp(p, "sh") == 0
3610 || fnamecmp(p, "ksh") == 0
3611 || fnamecmp(p, "zsh") == 0
3612 || fnamecmp(p, "bash") == 0
3613# ifdef WIN3264
3614 || fnamecmp(p, "cmd") == 0
3615 || fnamecmp(p, "sh.exe") == 0
3616 || fnamecmp(p, "ksh.exe") == 0
3617 || fnamecmp(p, "zsh.exe") == 0
3618 || fnamecmp(p, "bash.exe") == 0
3619 || fnamecmp(p, "cmd.exe") == 0
3620# endif
3621 )
3622# endif
3623 {
3624#if defined(FEAT_QUICKFIX)
3625 if (do_sp)
3626 {
3627# ifdef WIN3264
3628 p_sp = (char_u *)">%s 2>&1";
3629# else
3630 p_sp = (char_u *)"2>&1| tee";
3631# endif
3632 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3633 }
3634#endif
3635 if (do_srr)
3636 {
3637 p_srr = (char_u *)">%s 2>&1";
3638 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3639 }
3640 }
3641 vim_free(p);
3642 }
3643#endif
3644
3645#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3646 /*
3647 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3648 * This is done after other initializations, where 'shell' might have been
3649 * set, but only if they have not been set before. Default for p_shcf is
3650 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3651 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3652 * command.com. And for Win32 we need to set p_sxq instead.
3653 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003654 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 {
3656 int idx3;
3657
3658 idx3 = findoption((char_u *)"shcf");
3659 if (!(options[idx3].flags & P_WAS_SET))
3660 {
3661 p_shcf = (char_u *)"-c";
3662 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3663 }
3664
3665# ifndef DJGPP
3666# ifdef WIN3264
3667 /* Somehow Win32 requires the quotes around the redirection too */
3668 idx3 = findoption((char_u *)"sxq");
3669 if (!(options[idx3].flags & P_WAS_SET))
3670 {
3671 p_sxq = (char_u *)"\"";
3672 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3673 }
3674# else
3675 idx3 = findoption((char_u *)"shq");
3676 if (!(options[idx3].flags & P_WAS_SET))
3677 {
3678 p_shq = (char_u *)"\"";
3679 options[idx3].def_val[VI_DEFAULT] = p_shq;
3680 }
3681# endif
3682# endif
3683 }
3684#endif
3685
3686#ifdef FEAT_TITLE
3687 set_title_defaults();
3688#endif
3689}
3690
3691#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3692/*
3693 * When 'helplang' is still at its default value, set it to "lang".
3694 * Only the first two characters of "lang" are used.
3695 */
3696 void
3697set_helplang_default(lang)
3698 char_u *lang;
3699{
3700 int idx;
3701
3702 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3703 return;
3704 idx = findoption((char_u *)"hlg");
3705 if (!(options[idx].flags & P_WAS_SET))
3706 {
3707 if (options[idx].flags & P_ALLOCED)
3708 free_string_option(p_hlg);
3709 p_hlg = vim_strsave(lang);
3710 if (p_hlg == NULL)
3711 p_hlg = empty_option;
3712 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003713 {
3714 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3715 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3716 {
3717 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3718 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3719 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 options[idx].flags |= P_ALLOCED;
3723 }
3724}
3725#endif
3726
3727#ifdef FEAT_GUI
3728static char_u *gui_bg_default __ARGS((void));
3729
3730 static char_u *
3731gui_bg_default()
3732{
3733 if (gui_get_lightness(gui.back_pixel) < 127)
3734 return (char_u *)"dark";
3735 return (char_u *)"light";
3736}
3737
3738/*
3739 * Option initializations that can only be done after opening the GUI window.
3740 */
3741 void
3742init_gui_options()
3743{
3744 /* Set the 'background' option according to the lightness of the
3745 * background color, unless the user has set it already. */
3746 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3747 {
3748 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3749 highlight_changed();
3750 }
3751}
3752#endif
3753
3754#ifdef FEAT_TITLE
3755/*
3756 * 'title' and 'icon' only default to true if they have not been set or reset
3757 * in .vimrc and we can read the old value.
3758 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3759 * they can be reset. This reduces startup time when using X on a remote
3760 * machine.
3761 */
3762 void
3763set_title_defaults()
3764{
3765 int idx1;
3766 long val;
3767
3768 /*
3769 * If GUI is (going to be) used, we can always set the window title and
3770 * icon name. Saves a bit of time, because the X11 display server does
3771 * not need to be contacted.
3772 */
3773 idx1 = findoption((char_u *)"title");
3774 if (!(options[idx1].flags & P_WAS_SET))
3775 {
3776#ifdef FEAT_GUI
3777 if (gui.starting || gui.in_use)
3778 val = TRUE;
3779 else
3780#endif
3781 val = mch_can_restore_title();
3782 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3783 p_title = val;
3784 }
3785 idx1 = findoption((char_u *)"icon");
3786 if (!(options[idx1].flags & P_WAS_SET))
3787 {
3788#ifdef FEAT_GUI
3789 if (gui.starting || gui.in_use)
3790 val = TRUE;
3791 else
3792#endif
3793 val = mch_can_restore_icon();
3794 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3795 p_icon = val;
3796 }
3797}
3798#endif
3799
3800/*
3801 * Parse 'arg' for option settings.
3802 *
3803 * 'arg' may be IObuff, but only when no errors can be present and option
3804 * does not need to be expanded with option_expand().
3805 * "opt_flags":
3806 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003807 * OPT_GLOBAL for ":setglobal"
3808 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003810 * OPT_WINONLY to only set window-local options
3811 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812 *
3813 * returns FAIL if an error is detected, OK otherwise
3814 */
3815 int
3816do_set(arg, opt_flags)
3817 char_u *arg; /* option string (may be written to!) */
3818 int opt_flags;
3819{
3820 int opt_idx;
3821 char_u *errmsg;
3822 char_u errbuf[80];
3823 char_u *startarg;
3824 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3825 int nextchar; /* next non-white char after option name */
3826 int afterchar; /* character just after option name */
3827 int len;
3828 int i;
3829 long value;
3830 int key;
3831 long_u flags; /* flags for current option */
3832 char_u *varp = NULL; /* pointer to variable for current option */
3833 int did_show = FALSE; /* already showed one value */
3834 int adding; /* "opt+=arg" */
3835 int prepending; /* "opt^=arg" */
3836 int removing; /* "opt-=arg" */
3837 int cp_val = 0;
3838 char_u key_name[2];
3839
3840 if (*arg == NUL)
3841 {
3842 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003843 did_show = TRUE;
3844 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845 }
3846
3847 while (*arg != NUL) /* loop to process all options */
3848 {
3849 errmsg = NULL;
3850 startarg = arg; /* remember for error message */
3851
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003852 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3853 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 {
3855 /*
3856 * ":set all" show all options.
3857 * ":set all&" set all options to their default value.
3858 */
3859 arg += 3;
3860 if (*arg == '&')
3861 {
3862 ++arg;
3863 /* Only for :set command set global value of local options. */
3864 set_options_default(OPT_FREE | opt_flags);
3865 }
3866 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003867 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003869 did_show = TRUE;
3870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003872 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873 {
3874 showoptions(2, opt_flags);
3875 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003876 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 arg += 7;
3878 }
3879 else
3880 {
3881 prefix = 1;
3882 if (STRNCMP(arg, "no", 2) == 0)
3883 {
3884 prefix = 0;
3885 arg += 2;
3886 }
3887 else if (STRNCMP(arg, "inv", 3) == 0)
3888 {
3889 prefix = 2;
3890 arg += 3;
3891 }
3892
3893 /* find end of name */
3894 key = 0;
3895 if (*arg == '<')
3896 {
3897 nextchar = 0;
3898 opt_idx = -1;
3899 /* look out for <t_>;> */
3900 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3901 len = 5;
3902 else
3903 {
3904 len = 1;
3905 while (arg[len] != NUL && arg[len] != '>')
3906 ++len;
3907 }
3908 if (arg[len] != '>')
3909 {
3910 errmsg = e_invarg;
3911 goto skip;
3912 }
3913 arg[len] = NUL; /* put NUL after name */
3914 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3915 opt_idx = findoption(arg + 1);
3916 arg[len++] = '>'; /* restore '>' */
3917 if (opt_idx == -1)
3918 key = find_key_option(arg + 1);
3919 }
3920 else
3921 {
3922 len = 0;
3923 /*
3924 * The two characters after "t_" may not be alphanumeric.
3925 */
3926 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3927 len = 4;
3928 else
3929 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3930 ++len;
3931 nextchar = arg[len];
3932 arg[len] = NUL; /* put NUL after name */
3933 opt_idx = findoption(arg);
3934 arg[len] = nextchar; /* restore nextchar */
3935 if (opt_idx == -1)
3936 key = find_key_option(arg);
3937 }
3938
3939 /* remember character after option name */
3940 afterchar = arg[len];
3941
3942 /* skip white space, allow ":set ai ?" */
3943 while (vim_iswhite(arg[len]))
3944 ++len;
3945
3946 adding = FALSE;
3947 prepending = FALSE;
3948 removing = FALSE;
3949 if (arg[len] != NUL && arg[len + 1] == '=')
3950 {
3951 if (arg[len] == '+')
3952 {
3953 adding = TRUE; /* "+=" */
3954 ++len;
3955 }
3956 else if (arg[len] == '^')
3957 {
3958 prepending = TRUE; /* "^=" */
3959 ++len;
3960 }
3961 else if (arg[len] == '-')
3962 {
3963 removing = TRUE; /* "-=" */
3964 ++len;
3965 }
3966 }
3967 nextchar = arg[len];
3968
3969 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3970 {
3971 errmsg = (char_u *)N_("E518: Unknown option");
3972 goto skip;
3973 }
3974
3975 if (opt_idx >= 0)
3976 {
3977 if (options[opt_idx].var == NULL) /* hidden option: skip */
3978 {
3979 /* Only give an error message when requesting the value of
3980 * a hidden option, ignore setting it. */
3981 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3982 && (!(options[opt_idx].flags & P_BOOL)
3983 || nextchar == '?'))
3984 errmsg = (char_u *)N_("E519: Option not supported");
3985 goto skip;
3986 }
3987
3988 flags = options[opt_idx].flags;
3989 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3990 }
3991 else
3992 {
3993 flags = P_STRING;
3994 if (key < 0)
3995 {
3996 key_name[0] = KEY2TERMCAP0(key);
3997 key_name[1] = KEY2TERMCAP1(key);
3998 }
3999 else
4000 {
4001 key_name[0] = KS_KEY;
4002 key_name[1] = (key & 0xff);
4003 }
4004 }
4005
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004006 /* Skip all options that are not window-local (used when showing
4007 * an already loaded buffer in a window). */
4008 if ((opt_flags & OPT_WINONLY)
4009 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4010 goto skip;
4011
Bram Moolenaara3227e22006-03-08 21:32:40 +00004012 /* Skip all options that are window-local (used for :vimgrep). */
4013 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4014 && options[opt_idx].var == VAR_WIN)
4015 goto skip;
4016
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017 /* Disallow changing some options from modelines */
4018 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
4019 {
4020 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4021 goto skip;
4022 }
4023
4024#ifdef HAVE_SANDBOX
4025 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004026 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027 {
4028 errmsg = (char_u *)_(e_sandbox);
4029 goto skip;
4030 }
4031#endif
4032
4033 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4034 {
4035 arg += len;
4036 cp_val = p_cp;
4037 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4038 {
4039 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4040 {
4041 cp_val = FALSE;
4042 arg += 3;
4043 }
4044 else /* "opt&vi": set to Vi default */
4045 {
4046 cp_val = TRUE;
4047 arg += 2;
4048 }
4049 }
4050 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4051 && arg[1] != NUL && !vim_iswhite(arg[1]))
4052 {
4053 errmsg = e_trailing;
4054 goto skip;
4055 }
4056 }
4057
4058 /*
4059 * allow '=' and ':' as MSDOS command.com allows only one
4060 * '=' character per "set" command line. grrr. (jw)
4061 */
4062 if (nextchar == '?'
4063 || (prefix == 1
4064 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4065 && !(flags & P_BOOL)))
4066 {
4067 /*
4068 * print value
4069 */
4070 if (did_show)
4071 msg_putchar('\n'); /* cursor below last one */
4072 else
4073 {
4074 gotocmdline(TRUE); /* cursor at status line */
4075 did_show = TRUE; /* remember that we did a line */
4076 }
4077 if (opt_idx >= 0)
4078 {
4079 showoneopt(&options[opt_idx], opt_flags);
4080#ifdef FEAT_EVAL
4081 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004082 {
4083 /* Mention where the option was last set. */
4084 if (varp == options[opt_idx].var)
4085 last_set_msg(options[opt_idx].scriptID);
4086 else if ((int)options[opt_idx].indir & PV_WIN)
4087 last_set_msg(curwin->w_p_scriptID[
4088 (int)options[opt_idx].indir & PV_MASK]);
4089 else if ((int)options[opt_idx].indir & PV_BUF)
4090 last_set_msg(curbuf->b_p_scriptID[
4091 (int)options[opt_idx].indir & PV_MASK]);
4092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093#endif
4094 }
4095 else
4096 {
4097 char_u *p;
4098
4099 p = find_termcode(key_name);
4100 if (p == NULL)
4101 {
4102 errmsg = (char_u *)N_("E518: Unknown option");
4103 goto skip;
4104 }
4105 else
4106 (void)show_one_termcode(key_name, p, TRUE);
4107 }
4108 if (nextchar != '?'
4109 && nextchar != NUL && !vim_iswhite(afterchar))
4110 errmsg = e_trailing;
4111 }
4112 else
4113 {
4114 if (flags & P_BOOL) /* boolean */
4115 {
4116 if (nextchar == '=' || nextchar == ':')
4117 {
4118 errmsg = e_invarg;
4119 goto skip;
4120 }
4121
4122 /*
4123 * ":set opt!": invert
4124 * ":set opt&": reset to default value
4125 * ":set opt<": reset to global value
4126 */
4127 if (nextchar == '!')
4128 value = *(int *)(varp) ^ 1;
4129 else if (nextchar == '&')
4130 value = (int)(long)options[opt_idx].def_val[
4131 ((flags & P_VI_DEF) || cp_val)
4132 ? VI_DEFAULT : VIM_DEFAULT];
4133 else if (nextchar == '<')
4134 {
4135 /* For 'autoread' -1 means to use global value. */
4136 if ((int *)varp == &curbuf->b_p_ar
4137 && opt_flags == OPT_LOCAL)
4138 value = -1;
4139 else
4140 value = *(int *)get_varp_scope(&(options[opt_idx]),
4141 OPT_GLOBAL);
4142 }
4143 else
4144 {
4145 /*
4146 * ":set invopt": invert
4147 * ":set opt" or ":set noopt": set or reset
4148 */
4149 if (nextchar != NUL && !vim_iswhite(afterchar))
4150 {
4151 errmsg = e_trailing;
4152 goto skip;
4153 }
4154 if (prefix == 2) /* inv */
4155 value = *(int *)(varp) ^ 1;
4156 else
4157 value = prefix;
4158 }
4159
4160 errmsg = set_bool_option(opt_idx, varp, (int)value,
4161 opt_flags);
4162 }
4163 else /* numeric or string */
4164 {
4165 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4166 || prefix != 1)
4167 {
4168 errmsg = e_invarg;
4169 goto skip;
4170 }
4171
4172 if (flags & P_NUM) /* numeric */
4173 {
4174 /*
4175 * Different ways to set a number option:
4176 * & set to default value
4177 * < set to global value
4178 * <xx> accept special key codes for 'wildchar'
4179 * c accept any non-digit for 'wildchar'
4180 * [-]0-9 set number
4181 * other error
4182 */
4183 ++arg;
4184 if (nextchar == '&')
4185 value = (long)options[opt_idx].def_val[
4186 ((flags & P_VI_DEF) || cp_val)
4187 ? VI_DEFAULT : VIM_DEFAULT];
4188 else if (nextchar == '<')
4189 value = *(long *)get_varp_scope(&(options[opt_idx]),
4190 OPT_GLOBAL);
4191 else if (((long *)varp == &p_wc
4192 || (long *)varp == &p_wcm)
4193 && (*arg == '<'
4194 || *arg == '^'
4195 || ((!arg[1] || vim_iswhite(arg[1]))
4196 && !VIM_ISDIGIT(*arg))))
4197 {
4198 value = string_to_key(arg);
4199 if (value == 0 && (long *)varp != &p_wcm)
4200 {
4201 errmsg = e_invarg;
4202 goto skip;
4203 }
4204 }
4205 /* allow negative numbers (for 'undolevels') */
4206 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4207 {
4208 i = 0;
4209 if (*arg == '-')
4210 i = 1;
4211#ifdef HAVE_STRTOL
4212 value = strtol((char *)arg, NULL, 0);
4213 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4214 i += 2;
4215#else
4216 value = atol((char *)arg);
4217#endif
4218 while (VIM_ISDIGIT(arg[i]))
4219 ++i;
4220 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4221 {
4222 errmsg = e_invarg;
4223 goto skip;
4224 }
4225 }
4226 else
4227 {
4228 errmsg = (char_u *)N_("E521: Number required after =");
4229 goto skip;
4230 }
4231
4232 if (adding)
4233 value = *(long *)varp + value;
4234 if (prepending)
4235 value = *(long *)varp * value;
4236 if (removing)
4237 value = *(long *)varp - value;
4238 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004239 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 }
4241 else if (opt_idx >= 0) /* string */
4242 {
4243 char_u *save_arg = NULL;
4244 char_u *s = NULL;
4245 char_u *oldval; /* previous value if *varp */
4246 char_u *newval;
4247 char_u *origval;
4248 unsigned newlen;
4249 int comma;
4250 int bs;
4251 int new_value_alloced; /* new string option
4252 was allocated */
4253
4254 /* When using ":set opt=val" for a global option
4255 * with a local value the local value will be
4256 * reset, use the global value here. */
4257 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004258 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259 varp = options[opt_idx].var;
4260
4261 /* The old value is kept until we are sure that the
4262 * new value is valid. */
4263 oldval = *(char_u **)varp;
4264 if (nextchar == '&') /* set to default val */
4265 {
4266 newval = options[opt_idx].def_val[
4267 ((flags & P_VI_DEF) || cp_val)
4268 ? VI_DEFAULT : VIM_DEFAULT];
4269 if ((char_u **)varp == &p_bg)
4270 {
4271 /* guess the value of 'background' */
4272#ifdef FEAT_GUI
4273 if (gui.in_use)
4274 newval = gui_bg_default();
4275 else
4276#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004277 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278 }
4279
4280 /* expand environment variables and ~ (since the
4281 * default value was already expanded, only
4282 * required when an environment variable was set
4283 * later */
4284 if (newval == NULL)
4285 newval = empty_option;
4286 else
4287 {
4288 s = option_expand(opt_idx, newval);
4289 if (s == NULL)
4290 s = newval;
4291 newval = vim_strsave(s);
4292 }
4293 new_value_alloced = TRUE;
4294 }
4295 else if (nextchar == '<') /* set to global val */
4296 {
4297 newval = vim_strsave(*(char_u **)get_varp_scope(
4298 &(options[opt_idx]), OPT_GLOBAL));
4299 new_value_alloced = TRUE;
4300 }
4301 else
4302 {
4303 ++arg; /* jump to after the '=' or ':' */
4304
4305 /*
4306 * Set 'keywordprg' to ":help" if an empty
4307 * value was passed to :set by the user.
4308 * Misuse errbuf[] for the resulting string.
4309 */
4310 if (varp == (char_u *)&p_kp
4311 && (*arg == NUL || *arg == ' '))
4312 {
4313 STRCPY(errbuf, ":help");
4314 save_arg = arg;
4315 arg = errbuf;
4316 }
4317 /*
4318 * Convert 'whichwrap' number to string, for
4319 * backwards compatibility with Vim 3.0.
4320 * Misuse errbuf[] for the resulting string.
4321 */
4322 else if (varp == (char_u *)&p_ww
4323 && VIM_ISDIGIT(*arg))
4324 {
4325 *errbuf = NUL;
4326 i = getdigits(&arg);
4327 if (i & 1)
4328 STRCAT(errbuf, "b,");
4329 if (i & 2)
4330 STRCAT(errbuf, "s,");
4331 if (i & 4)
4332 STRCAT(errbuf, "h,l,");
4333 if (i & 8)
4334 STRCAT(errbuf, "<,>,");
4335 if (i & 16)
4336 STRCAT(errbuf, "[,],");
4337 if (*errbuf != NUL) /* remove trailing , */
4338 errbuf[STRLEN(errbuf) - 1] = NUL;
4339 save_arg = arg;
4340 arg = errbuf;
4341 }
4342 /*
4343 * Remove '>' before 'dir' and 'bdir', for
4344 * backwards compatibility with version 3.0
4345 */
4346 else if ( *arg == '>'
4347 && (varp == (char_u *)&p_dir
4348 || varp == (char_u *)&p_bdir))
4349 {
4350 ++arg;
4351 }
4352
4353 /* When setting the local value of a global
4354 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004355 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 && (opt_flags & OPT_LOCAL))
4357 origval = *(char_u **)get_varp(
4358 &options[opt_idx]);
4359 else
4360 origval = oldval;
4361
4362 /*
4363 * Copy the new string into allocated memory.
4364 * Can't use set_string_option_direct(), because
4365 * we need to remove the backslashes.
4366 */
4367 /* get a bit too much */
4368 newlen = (unsigned)STRLEN(arg) + 1;
4369 if (adding || prepending || removing)
4370 newlen += (unsigned)STRLEN(origval) + 1;
4371 newval = alloc(newlen);
4372 if (newval == NULL) /* out of mem, don't change */
4373 break;
4374 s = newval;
4375
4376 /*
4377 * Copy the string, skip over escaped chars.
4378 * For MS-DOS and WIN32 backslashes before normal
4379 * file name characters are not removed, and keep
4380 * backslash at start, for "\\machine\path", but
4381 * do remove it for "\\\\machine\\path".
4382 * The reverse is found in ExpandOldSetting().
4383 */
4384 while (*arg && !vim_iswhite(*arg))
4385 {
4386 if (*arg == '\\' && arg[1] != NUL
4387#ifdef BACKSLASH_IN_FILENAME
4388 && !((flags & P_EXPAND)
4389 && vim_isfilec(arg[1])
4390 && (arg[1] != '\\'
4391 || (s == newval
4392 && arg[2] != '\\')))
4393#endif
4394 )
4395 ++arg; /* remove backslash */
4396#ifdef FEAT_MBYTE
4397 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004398 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 {
4400 /* copy multibyte char */
4401 mch_memmove(s, arg, (size_t)i);
4402 arg += i;
4403 s += i;
4404 }
4405 else
4406#endif
4407 *s++ = *arg++;
4408 }
4409 *s = NUL;
4410
4411 /*
4412 * Expand environment variables and ~.
4413 * Don't do it when adding without inserting a
4414 * comma.
4415 */
4416 if (!(adding || prepending || removing)
4417 || (flags & P_COMMA))
4418 {
4419 s = option_expand(opt_idx, newval);
4420 if (s != NULL)
4421 {
4422 vim_free(newval);
4423 newlen = (unsigned)STRLEN(s) + 1;
4424 if (adding || prepending || removing)
4425 newlen += (unsigned)STRLEN(origval) + 1;
4426 newval = alloc(newlen);
4427 if (newval == NULL)
4428 break;
4429 STRCPY(newval, s);
4430 }
4431 }
4432
4433 /* locate newval[] in origval[] when removing it
4434 * and when adding to avoid duplicates */
4435 i = 0; /* init for GCC */
4436 if (removing || (flags & P_NODUP))
4437 {
4438 i = (int)STRLEN(newval);
4439 bs = 0;
4440 for (s = origval; *s; ++s)
4441 {
4442 if ((!(flags & P_COMMA)
4443 || s == origval
4444 || (s[-1] == ',' && !(bs & 1)))
4445 && STRNCMP(s, newval, i) == 0
4446 && (!(flags & P_COMMA)
4447 || s[i] == ','
4448 || s[i] == NUL))
4449 break;
4450 /* Count backspaces. Only a comma with an
4451 * even number of backspaces before it is
4452 * recognized as a separator */
4453 if (s > origval && s[-1] == '\\')
4454 ++bs;
4455 else
4456 bs = 0;
4457 }
4458
4459 /* do not add if already there */
4460 if ((adding || prepending) && *s)
4461 {
4462 prepending = FALSE;
4463 adding = FALSE;
4464 STRCPY(newval, origval);
4465 }
4466 }
4467
4468 /* concatenate the two strings; add a ',' if
4469 * needed */
4470 if (adding || prepending)
4471 {
4472 comma = ((flags & P_COMMA) && *origval != NUL
4473 && *newval != NUL);
4474 if (adding)
4475 {
4476 i = (int)STRLEN(origval);
4477 mch_memmove(newval + i + comma, newval,
4478 STRLEN(newval) + 1);
4479 mch_memmove(newval, origval, (size_t)i);
4480 }
4481 else
4482 {
4483 i = (int)STRLEN(newval);
4484 mch_memmove(newval + i + comma, origval,
4485 STRLEN(origval) + 1);
4486 }
4487 if (comma)
4488 newval[i] = ',';
4489 }
4490
4491 /* Remove newval[] from origval[]. (Note: "i" has
4492 * been set above and is used here). */
4493 if (removing)
4494 {
4495 STRCPY(newval, origval);
4496 if (*s)
4497 {
4498 /* may need to remove a comma */
4499 if (flags & P_COMMA)
4500 {
4501 if (s == origval)
4502 {
4503 /* include comma after string */
4504 if (s[i] == ',')
4505 ++i;
4506 }
4507 else
4508 {
4509 /* include comma before string */
4510 --s;
4511 ++i;
4512 }
4513 }
4514 mch_memmove(newval + (s - origval), s + i,
4515 STRLEN(s + i) + 1);
4516 }
4517 }
4518
4519 if (flags & P_FLAGLIST)
4520 {
4521 /* Remove flags that appear twice. */
4522 for (s = newval; *s; ++s)
4523 if ((!(flags & P_COMMA) || *s != ',')
4524 && vim_strchr(s + 1, *s) != NULL)
4525 {
4526 STRCPY(s, s + 1);
4527 --s;
4528 }
4529 }
4530
4531 if (save_arg != NULL) /* number for 'whichwrap' */
4532 arg = save_arg;
4533 new_value_alloced = TRUE;
4534 }
4535
4536 /* Set the new value. */
4537 *(char_u **)(varp) = newval;
4538
4539 /* Handle side effects, and set the global value for
4540 * ":set" on local options. */
4541 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4542 new_value_alloced, oldval, errbuf, opt_flags);
4543
4544 /* If error detected, print the error message. */
4545 if (errmsg != NULL)
4546 goto skip;
4547 }
4548 else /* key code option */
4549 {
4550 char_u *p;
4551
4552 if (nextchar == '&')
4553 {
4554 if (add_termcap_entry(key_name, TRUE) == FAIL)
4555 errmsg = (char_u *)N_("E522: Not found in termcap");
4556 }
4557 else
4558 {
4559 ++arg; /* jump to after the '=' or ':' */
4560 for (p = arg; *p && !vim_iswhite(*p); ++p)
4561 if (*p == '\\' && p[1] != NUL)
4562 ++p;
4563 nextchar = *p;
4564 *p = NUL;
4565 add_termcode(key_name, arg, FALSE);
4566 *p = nextchar;
4567 }
4568 if (full_screen)
4569 ttest(FALSE);
4570 redraw_all_later(CLEAR);
4571 }
4572 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004573
Bram Moolenaar071d4272004-06-13 20:20:40 +00004574 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004575 did_set_option(opt_idx, opt_flags,
4576 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004577 }
4578
4579skip:
4580 /*
4581 * Advance to next argument.
4582 * - skip until a blank found, taking care of backslashes
4583 * - skip blanks
4584 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4585 */
4586 for (i = 0; i < 2 ; ++i)
4587 {
4588 while (*arg != NUL && !vim_iswhite(*arg))
4589 if (*arg++ == '\\' && *arg != NUL)
4590 ++arg;
4591 arg = skipwhite(arg);
4592 if (*arg != '=')
4593 break;
4594 }
4595 }
4596
4597 if (errmsg != NULL)
4598 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004599 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600 i = STRLEN(IObuff) + 2;
4601 if (i + (arg - startarg) < IOSIZE)
4602 {
4603 /* append the argument with the error */
4604 STRCAT(IObuff, ": ");
4605 mch_memmove(IObuff + i, startarg, (arg - startarg));
4606 IObuff[i + (arg - startarg)] = NUL;
4607 }
4608 /* make sure all characters are printable */
4609 trans_characters(IObuff, IOSIZE);
4610
4611 ++no_wait_return; /* wait_return done later */
4612 emsg(IObuff); /* show error highlighted */
4613 --no_wait_return;
4614
4615 return FAIL;
4616 }
4617
4618 arg = skipwhite(arg);
4619 }
4620
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004621theend:
4622 if (silent_mode && did_show)
4623 {
4624 /* After displaying option values in silent mode. */
4625 silent_mode = FALSE;
4626 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4627 msg_putchar('\n');
4628 cursor_on(); /* msg_start() switches it off */
4629 out_flush();
4630 silent_mode = TRUE;
4631 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4632 }
4633
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634 return OK;
4635}
4636
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004637/*
4638 * Call this when an option has been given a new value through a user command.
4639 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4640 */
4641 static void
4642did_set_option(opt_idx, opt_flags, new_value)
4643 int opt_idx;
4644 int opt_flags; /* possibly with OPT_MODELINE */
4645 int new_value; /* value was replaced completely */
4646{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004647 long_u *p;
4648
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004649 options[opt_idx].flags |= P_WAS_SET;
4650
4651 /* When an option is set in the sandbox, from a modeline or in secure mode
4652 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004653 * flag. */
4654 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004655 if (secure
4656#ifdef HAVE_SANDBOX
4657 || sandbox != 0
4658#endif
4659 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004660 *p = *p | P_INSECURE;
4661 else if (new_value)
4662 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004663}
4664
Bram Moolenaar071d4272004-06-13 20:20:40 +00004665 static char_u *
4666illegal_char(errbuf, c)
4667 char_u *errbuf;
4668 int c;
4669{
4670 if (errbuf == NULL)
4671 return (char_u *)"";
4672 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004673 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004674 return errbuf;
4675}
4676
4677/*
4678 * Convert a key name or string into a key value.
4679 * Used for 'wildchar' and 'cedit' options.
4680 */
4681 static int
4682string_to_key(arg)
4683 char_u *arg;
4684{
4685 if (*arg == '<')
4686 return find_key_option(arg + 1);
4687 if (*arg == '^')
4688 return Ctrl_chr(arg[1]);
4689 return *arg;
4690}
4691
4692#ifdef FEAT_CMDWIN
4693/*
4694 * Check value of 'cedit' and set cedit_key.
4695 * Returns NULL if value is OK, error message otherwise.
4696 */
4697 static char_u *
4698check_cedit()
4699{
4700 int n;
4701
4702 if (*p_cedit == NUL)
4703 cedit_key = -1;
4704 else
4705 {
4706 n = string_to_key(p_cedit);
4707 if (vim_isprintc(n))
4708 return e_invarg;
4709 cedit_key = n;
4710 }
4711 return NULL;
4712}
4713#endif
4714
4715#ifdef FEAT_TITLE
4716/*
4717 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4718 * maketitle() to create and display it.
4719 * When switching the title or icon off, call mch_restore_title() to get
4720 * the old value back.
4721 */
4722 static void
4723did_set_title(icon)
4724 int icon; /* Did set icon instead of title */
4725{
4726 if (starting != NO_SCREEN
4727#ifdef FEAT_GUI
4728 && !gui.starting
4729#endif
4730 )
4731 {
4732 maketitle();
4733 if (icon)
4734 {
4735 if (!p_icon)
4736 mch_restore_title(2);
4737 }
4738 else
4739 {
4740 if (!p_title)
4741 mch_restore_title(1);
4742 }
4743 }
4744}
4745#endif
4746
4747/*
4748 * set_options_bin - called when 'bin' changes value.
4749 */
4750 void
4751set_options_bin(oldval, newval, opt_flags)
4752 int oldval;
4753 int newval;
4754 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4755{
4756 /*
4757 * The option values that are changed when 'bin' changes are
4758 * copied when 'bin is set and restored when 'bin' is reset.
4759 */
4760 if (newval)
4761 {
4762 if (!oldval) /* switched on */
4763 {
4764 if (!(opt_flags & OPT_GLOBAL))
4765 {
4766 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4767 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4768 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4769 curbuf->b_p_et_nobin = curbuf->b_p_et;
4770 }
4771 if (!(opt_flags & OPT_LOCAL))
4772 {
4773 p_tw_nobin = p_tw;
4774 p_wm_nobin = p_wm;
4775 p_ml_nobin = p_ml;
4776 p_et_nobin = p_et;
4777 }
4778 }
4779
4780 if (!(opt_flags & OPT_GLOBAL))
4781 {
4782 curbuf->b_p_tw = 0; /* no automatic line wrap */
4783 curbuf->b_p_wm = 0; /* no automatic line wrap */
4784 curbuf->b_p_ml = 0; /* no modelines */
4785 curbuf->b_p_et = 0; /* no expandtab */
4786 }
4787 if (!(opt_flags & OPT_LOCAL))
4788 {
4789 p_tw = 0;
4790 p_wm = 0;
4791 p_ml = FALSE;
4792 p_et = FALSE;
4793 p_bin = TRUE; /* needed when called for the "-b" argument */
4794 }
4795 }
4796 else if (oldval) /* switched off */
4797 {
4798 if (!(opt_flags & OPT_GLOBAL))
4799 {
4800 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4801 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4802 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4803 curbuf->b_p_et = curbuf->b_p_et_nobin;
4804 }
4805 if (!(opt_flags & OPT_LOCAL))
4806 {
4807 p_tw = p_tw_nobin;
4808 p_wm = p_wm_nobin;
4809 p_ml = p_ml_nobin;
4810 p_et = p_et_nobin;
4811 }
4812 }
4813}
4814
4815#ifdef FEAT_VIMINFO
4816/*
4817 * Find the parameter represented by the given character (eg ', :, ", or /),
4818 * and return its associated value in the 'viminfo' string.
4819 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004820 * If the parameter is not specified in the string or there is no following
4821 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 */
4823 int
4824get_viminfo_parameter(type)
4825 int type;
4826{
4827 char_u *p;
4828
4829 p = find_viminfo_parameter(type);
4830 if (p != NULL && VIM_ISDIGIT(*p))
4831 return atoi((char *)p);
4832 return -1;
4833}
4834
4835/*
4836 * Find the parameter represented by the given character (eg ''', ':', '"', or
4837 * '/') in the 'viminfo' option and return a pointer to the string after it.
4838 * Return NULL if the parameter is not specified in the string.
4839 */
4840 char_u *
4841find_viminfo_parameter(type)
4842 int type;
4843{
4844 char_u *p;
4845
4846 for (p = p_viminfo; *p; ++p)
4847 {
4848 if (*p == type)
4849 return p + 1;
4850 if (*p == 'n') /* 'n' is always the last one */
4851 break;
4852 p = vim_strchr(p, ','); /* skip until next ',' */
4853 if (p == NULL) /* hit the end without finding parameter */
4854 break;
4855 }
4856 return NULL;
4857}
4858#endif
4859
4860/*
4861 * Expand environment variables for some string options.
4862 * These string options cannot be indirect!
4863 * If "val" is NULL expand the current value of the option.
4864 * Return pointer to NameBuff, or NULL when not expanded.
4865 */
4866 static char_u *
4867option_expand(opt_idx, val)
4868 int opt_idx;
4869 char_u *val;
4870{
4871 /* if option doesn't need expansion nothing to do */
4872 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4873 return NULL;
4874
4875 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4876 * expand_env() would truncate the string. */
4877 if (val != NULL && STRLEN(val) > MAXPATHL)
4878 return NULL;
4879
4880 if (val == NULL)
4881 val = *(char_u **)options[opt_idx].var;
4882
4883 /*
4884 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4885 * Escape spaces when expanding 'tags', they are used to separate file
4886 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004887 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 */
4889 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004890 (char_u **)options[opt_idx].var == &p_tags,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00004891#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004892 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4893#endif
4894 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004895 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4896 return NULL;
4897
4898 return NameBuff;
4899}
4900
4901/*
4902 * After setting various option values: recompute variables that depend on
4903 * option values.
4904 */
4905 static void
4906didset_options()
4907{
4908 /* initialize the table for 'iskeyword' et.al. */
4909 (void)init_chartab();
4910
4911 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4912 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4913#ifdef FEAT_SESSION
4914 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4915 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4916#endif
4917#ifdef FEAT_FOLDING
4918 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4919#endif
4920 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4921#ifdef FEAT_VIRTUALEDIT
4922 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4923#endif
4924#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4925 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4926#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00004927#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004928 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004929 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004930 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4933 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4934#endif
4935#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4936 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4937#endif
4938#ifdef FEAT_CMDWIN
4939 /* set cedit_key */
4940 (void)check_cedit();
4941#endif
4942}
4943
4944/*
4945 * Check for string options that are NULL (normally only termcap options).
4946 */
4947 void
4948check_options()
4949{
4950 int opt_idx;
4951
4952 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4953 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4954 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4955}
4956
4957/*
4958 * Check string options in a buffer for NULL value.
4959 */
4960 void
4961check_buf_options(buf)
4962 buf_T *buf;
4963{
4964#if defined(FEAT_QUICKFIX)
4965 check_string_option(&buf->b_p_bh);
4966 check_string_option(&buf->b_p_bt);
4967#endif
4968#ifdef FEAT_MBYTE
4969 check_string_option(&buf->b_p_fenc);
4970#endif
4971 check_string_option(&buf->b_p_ff);
4972#ifdef FEAT_FIND_ID
4973 check_string_option(&buf->b_p_def);
4974 check_string_option(&buf->b_p_inc);
4975# ifdef FEAT_EVAL
4976 check_string_option(&buf->b_p_inex);
4977# endif
4978#endif
4979#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4980 check_string_option(&buf->b_p_inde);
4981 check_string_option(&buf->b_p_indk);
4982#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00004983#if defined(FEAT_EVAL)
4984 check_string_option(&buf->b_p_fex);
4985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986#ifdef FEAT_CRYPT
4987 check_string_option(&buf->b_p_key);
4988#endif
4989 check_string_option(&buf->b_p_kp);
4990 check_string_option(&buf->b_p_mps);
4991 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004992 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004993 check_string_option(&buf->b_p_isk);
4994#ifdef FEAT_COMMENTS
4995 check_string_option(&buf->b_p_com);
4996#endif
4997#ifdef FEAT_FOLDING
4998 check_string_option(&buf->b_p_cms);
4999#endif
5000 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005001#ifdef FEAT_TEXTOBJ
5002 check_string_option(&buf->b_p_qe);
5003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005004#ifdef FEAT_SYN_HL
5005 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005006#endif
5007#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005008 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005009 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005010 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005011#endif
5012#ifdef FEAT_SEARCHPATH
5013 check_string_option(&buf->b_p_sua);
5014#endif
5015#ifdef FEAT_CINDENT
5016 check_string_option(&buf->b_p_cink);
5017 check_string_option(&buf->b_p_cino);
5018#endif
5019#ifdef FEAT_AUTOCMD
5020 check_string_option(&buf->b_p_ft);
5021#endif
5022#ifdef FEAT_OSFILETYPE
5023 check_string_option(&buf->b_p_oft);
5024#endif
5025#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5026 check_string_option(&buf->b_p_cinw);
5027#endif
5028#ifdef FEAT_INS_EXPAND
5029 check_string_option(&buf->b_p_cpt);
5030#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005031#ifdef FEAT_COMPL_FUNC
5032 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005033 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005035#ifdef FEAT_KEYMAP
5036 check_string_option(&buf->b_p_keymap);
5037#endif
5038#ifdef FEAT_QUICKFIX
5039 check_string_option(&buf->b_p_gp);
5040 check_string_option(&buf->b_p_mp);
5041 check_string_option(&buf->b_p_efm);
5042#endif
5043 check_string_option(&buf->b_p_ep);
5044 check_string_option(&buf->b_p_path);
5045 check_string_option(&buf->b_p_tags);
5046#ifdef FEAT_INS_EXPAND
5047 check_string_option(&buf->b_p_dict);
5048 check_string_option(&buf->b_p_tsr);
5049#endif
5050}
5051
5052/*
5053 * Free the string allocated for an option.
5054 * Checks for the string being empty_option. This may happen if we're out of
5055 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5056 * check_options().
5057 * Does NOT check for P_ALLOCED flag!
5058 */
5059 void
5060free_string_option(p)
5061 char_u *p;
5062{
5063 if (p != empty_option)
5064 vim_free(p);
5065}
5066
5067 void
5068clear_string_option(pp)
5069 char_u **pp;
5070{
5071 if (*pp != empty_option)
5072 vim_free(*pp);
5073 *pp = empty_option;
5074}
5075
5076 static void
5077check_string_option(pp)
5078 char_u **pp;
5079{
5080 if (*pp == NULL)
5081 *pp = empty_option;
5082}
5083
5084/*
5085 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5086 */
5087 void
5088set_term_option_alloced(p)
5089 char_u **p;
5090{
5091 int opt_idx;
5092
5093 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5094 if (options[opt_idx].var == (char_u *)p)
5095 {
5096 options[opt_idx].flags |= P_ALLOCED;
5097 return;
5098 }
5099 return; /* cannot happen: didn't find it! */
5100}
5101
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005102#if defined(FEAT_EVAL) || defined(PROTO)
5103/*
5104 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5105 * Return FALSE when it wasn't.
5106 * Return -1 for an unknown option.
5107 */
5108 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005109was_set_insecurely(opt, opt_flags)
5110 char_u *opt;
5111 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005112{
5113 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005114 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005115
5116 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005117 {
5118 flagp = insecure_flag(idx, opt_flags);
5119 return (*flagp & P_INSECURE) != 0;
5120 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005121 EMSG2(_(e_intern2), "was_set_insecurely()");
5122 return -1;
5123}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005124
5125/*
5126 * Get a pointer to the flags used for the P_INSECURE flag of option
5127 * "opt_idx". For some local options a local flags field is used.
5128 */
5129 static long_u *
5130insecure_flag(opt_idx, opt_flags)
5131 int opt_idx;
5132 int opt_flags;
5133{
5134 if (opt_flags & OPT_LOCAL)
5135 switch ((int)options[opt_idx].indir)
5136 {
5137#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005138 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005139#endif
5140#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005141 case PV_FDE: return &curwin->w_p_fde_flags;
5142 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005143#endif
5144#if defined(FEAT_EVAL)
5145# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005146 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005147# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005148 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005149# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005150 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005151# endif
5152#endif
5153 }
5154
5155 /* Nothing special, return global flags field. */
5156 return &options[opt_idx].flags;
5157}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005158#endif
5159
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160/*
5161 * Set a string option to a new value (without checking the effect).
5162 * The string is copied into allocated memory.
5163 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005164 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5165 * SID_NONE don't set the scriptID. Otherwose set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005167/*ARGSUSED*/
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005169set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170 char_u *name;
5171 int opt_idx;
5172 char_u *val;
5173 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005174 int set_sid;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175{
5176 char_u *s;
5177 char_u **varp;
5178 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5179
5180 if (opt_idx == -1) /* use name */
5181 {
5182 opt_idx = findoption(name);
5183 if (opt_idx == -1) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005184 {
5185 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005187 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005188 }
5189
5190 if (options[opt_idx].var == NULL) /* can't set hidden option */
5191 return;
5192
5193 s = vim_strsave(val);
5194 if (s != NULL)
5195 {
5196 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5197 both ? OPT_LOCAL : opt_flags);
5198 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
5199 free_string_option(*varp);
5200 *varp = s;
5201
5202 /* For buffer/window local option may also set the global value. */
5203 if (both)
5204 set_string_option_global(opt_idx, varp);
5205
5206 options[opt_idx].flags |= P_ALLOCED;
5207
5208 /* When setting both values of a global option with a local value,
5209 * make the local value empty, so that the global value is used. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005210 if (((int)options[opt_idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 {
5212 free_string_option(*varp);
5213 *varp = empty_option;
5214 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005215# ifdef FEAT_EVAL
5216 if (set_sid != SID_NONE)
5217 set_option_scriptID_idx(opt_idx, opt_flags,
5218 set_sid == 0 ? current_SID : set_sid);
5219# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 }
5221}
5222
5223/*
5224 * Set global value for string option when it's a local option.
5225 */
5226 static void
5227set_string_option_global(opt_idx, varp)
5228 int opt_idx; /* option index */
5229 char_u **varp; /* pointer to option variable */
5230{
5231 char_u **p, *s;
5232
5233 /* the global value is always allocated */
5234 if (options[opt_idx].var == VAR_WIN)
5235 p = (char_u **)GLOBAL_WO(varp);
5236 else
5237 p = (char_u **)options[opt_idx].var;
5238 if (options[opt_idx].indir != PV_NONE
5239 && p != varp
5240 && (s = vim_strsave(*varp)) != NULL)
5241 {
5242 free_string_option(*p);
5243 *p = s;
5244 }
5245}
5246
5247/*
5248 * Set a string option to a new value, and handle the effects.
5249 */
5250 static void
5251set_string_option(opt_idx, value, opt_flags)
5252 int opt_idx;
5253 char_u *value;
5254 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5255{
5256 char_u *s;
5257 char_u **varp;
5258 char_u *oldval;
5259
5260 if (options[opt_idx].var == NULL) /* don't set hidden option */
5261 return;
5262
5263 s = vim_strsave(value);
5264 if (s != NULL)
5265 {
5266 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5267 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005268 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005269 ? OPT_GLOBAL : OPT_LOCAL)
5270 : opt_flags);
5271 oldval = *varp;
5272 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005273 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5274 opt_flags) == NULL)
5275 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005276 }
5277}
5278
5279/*
5280 * Handle string options that need some action to perform when changed.
5281 * Returns NULL for success, or an error message for an error.
5282 */
5283 static char_u *
5284did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5285 opt_flags)
5286 int opt_idx; /* index in options[] table */
5287 char_u **varp; /* pointer to the option variable */
5288 int new_value_alloced; /* new value was allocated */
5289 char_u *oldval; /* previous value of the option */
5290 char_u *errbuf; /* buffer for errors, or NULL */
5291 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5292{
5293 char_u *errmsg = NULL;
5294 char_u *s, *p;
5295 int did_chartab = FALSE;
5296 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005297 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298
5299 /* Get the global option to compare with, otherwise we would have to check
5300 * two values for all local options. */
5301 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5302
5303 /* Disallow changing some options from secure mode */
5304 if ((secure
5305#ifdef HAVE_SANDBOX
5306 || sandbox != 0
5307#endif
5308 ) && (options[opt_idx].flags & P_SECURE))
5309 {
5310 errmsg = e_secure;
5311 }
5312
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005313 /* Check for a "normal" file name in some options. Disallow a path
5314 * separator (slash and/or backslash), wildcards and characters that are
5315 * often illegal in a file name. */
5316 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005317 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005318 {
5319 errmsg = e_invarg;
5320 }
5321
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 /* 'term' */
5323 else if (varp == &T_NAME)
5324 {
5325 if (T_NAME[0] == NUL)
5326 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5327#ifdef FEAT_GUI
5328 if (gui.in_use)
5329 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5330 else if (term_is_gui(T_NAME))
5331 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5332#endif
5333 else if (set_termname(T_NAME) == FAIL)
5334 errmsg = (char_u *)N_("E522: Not found in termcap");
5335 else
5336 /* Screen colors may have changed. */
5337 redraw_later_clear();
5338 }
5339
5340 /* 'backupcopy' */
5341 else if (varp == &p_bkc)
5342 {
5343 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5344 errmsg = e_invarg;
5345 if (((bkc_flags & BKC_AUTO) != 0)
5346 + ((bkc_flags & BKC_YES) != 0)
5347 + ((bkc_flags & BKC_NO) != 0) != 1)
5348 {
5349 /* Must have exactly one of "auto", "yes" and "no". */
5350 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5351 errmsg = e_invarg;
5352 }
5353 }
5354
5355 /* 'backupext' and 'patchmode' */
5356 else if (varp == &p_bex || varp == &p_pm)
5357 {
5358 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5359 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5360 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5361 }
5362
5363 /*
5364 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5365 * If the new option is invalid, use old value. 'lisp' option: refill
5366 * chartab[] for '-' char
5367 */
5368 else if ( varp == &p_isi
5369 || varp == &(curbuf->b_p_isk)
5370 || varp == &p_isp
5371 || varp == &p_isf)
5372 {
5373 if (init_chartab() == FAIL)
5374 {
5375 did_chartab = TRUE; /* need to restore it below */
5376 errmsg = e_invarg; /* error in value */
5377 }
5378 }
5379
5380 /* 'helpfile' */
5381 else if (varp == &p_hf)
5382 {
5383 /* May compute new values for $VIM and $VIMRUNTIME */
5384 if (didset_vim)
5385 {
5386 vim_setenv((char_u *)"VIM", (char_u *)"");
5387 didset_vim = FALSE;
5388 }
5389 if (didset_vimruntime)
5390 {
5391 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5392 didset_vimruntime = FALSE;
5393 }
5394 }
5395
5396#ifdef FEAT_MULTI_LANG
5397 /* 'helplang' */
5398 else if (varp == &p_hlg)
5399 {
5400 /* Check for "", "ab", "ab,cd", etc. */
5401 for (s = p_hlg; *s != NUL; s += 3)
5402 {
5403 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5404 {
5405 errmsg = e_invarg;
5406 break;
5407 }
5408 if (s[2] == NUL)
5409 break;
5410 }
5411 }
5412#endif
5413
5414 /* 'highlight' */
5415 else if (varp == &p_hl)
5416 {
5417 if (highlight_changed() == FAIL)
5418 errmsg = e_invarg; /* invalid flags */
5419 }
5420
5421 /* 'nrformats' */
5422 else if (gvarp == &p_nf)
5423 {
5424 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5425 errmsg = e_invarg;
5426 }
5427
5428#ifdef FEAT_SESSION
5429 /* 'sessionoptions' */
5430 else if (varp == &p_ssop)
5431 {
5432 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5433 errmsg = e_invarg;
5434 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5435 {
5436 /* Don't allow both "sesdir" and "curdir". */
5437 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5438 errmsg = e_invarg;
5439 }
5440 }
5441 /* 'viewoptions' */
5442 else if (varp == &p_vop)
5443 {
5444 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5445 errmsg = e_invarg;
5446 }
5447#endif
5448
5449 /* 'scrollopt' */
5450#ifdef FEAT_SCROLLBIND
5451 else if (varp == &p_sbo)
5452 {
5453 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5454 errmsg = e_invarg;
5455 }
5456#endif
5457
5458 /* 'ambiwidth' */
5459#ifdef FEAT_MBYTE
5460 else if (varp == &p_ambw)
5461 {
5462 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5463 errmsg = e_invarg;
5464 }
5465#endif
5466
5467 /* 'background' */
5468 else if (varp == &p_bg)
5469 {
5470 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5471 {
5472#ifdef FEAT_EVAL
5473 int dark = (*p_bg == 'd');
5474#endif
5475
5476 init_highlight(FALSE, FALSE);
5477
5478#ifdef FEAT_EVAL
5479 if (dark != (*p_bg == 'd')
5480 && get_var_value((char_u *)"g:colors_name") != NULL)
5481 {
5482 /* The color scheme must have set 'background' back to another
5483 * value, that's not what we want here. Disable the color
5484 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005485 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486 free_string_option(p_bg);
5487 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5488 check_string_option(&p_bg);
5489 init_highlight(FALSE, FALSE);
5490 }
5491#endif
5492 }
5493 else
5494 errmsg = e_invarg;
5495 }
5496
5497 /* 'wildmode' */
5498 else if (varp == &p_wim)
5499 {
5500 if (check_opt_wim() == FAIL)
5501 errmsg = e_invarg;
5502 }
5503
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005504#ifdef FEAT_CMDL_COMPL
5505 /* 'wildoptions' */
5506 else if (varp == &p_wop)
5507 {
5508 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5509 errmsg = e_invarg;
5510 }
5511#endif
5512
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513#ifdef FEAT_WAK
5514 /* 'winaltkeys' */
5515 else if (varp == &p_wak)
5516 {
5517 if (*p_wak == NUL
5518 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5519 errmsg = e_invarg;
5520# ifdef FEAT_MENU
5521# ifdef FEAT_GUI_MOTIF
5522 else if (gui.in_use)
5523 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5524# else
5525# ifdef FEAT_GUI_GTK
5526 else if (gui.in_use)
5527 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5528# endif
5529# endif
5530# endif
5531 }
5532#endif
5533
5534#ifdef FEAT_AUTOCMD
5535 /* 'eventignore' */
5536 else if (varp == &p_ei)
5537 {
5538 if (check_ei() == FAIL)
5539 errmsg = e_invarg;
5540 }
5541#endif
5542
5543#ifdef FEAT_MBYTE
5544 /* 'encoding' and 'fileencoding' */
5545 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5546 {
5547 if (gvarp == &p_fenc)
5548 {
5549 if (!curbuf->b_p_ma)
5550 errmsg = e_modifiable;
5551 else if (vim_strchr(*varp, ',') != NULL)
5552 /* No comma allowed in 'fileencoding'; catches confusing it
5553 * with 'fileencodings'. */
5554 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005556 {
5557# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 /* May show a "+" in the title now. */
5559 need_maketitle = TRUE;
5560# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005561 /* Add 'fileencoding' to the swap file. */
5562 ml_setflags(curbuf);
5563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 }
5565 if (errmsg == NULL)
5566 {
5567 /* canonize the value, so that STRCMP() can be used on it */
5568 p = enc_canonize(*varp);
5569 if (p != NULL)
5570 {
5571 vim_free(*varp);
5572 *varp = p;
5573 }
5574 if (varp == &p_enc)
5575 {
5576 errmsg = mb_init();
5577# ifdef FEAT_TITLE
5578 need_maketitle = TRUE;
5579# endif
5580 }
5581 }
5582
5583# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5584 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5585 {
5586 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5587 if (STRCMP(p_tenc, "utf-8") != 0)
5588 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5589 }
5590# endif
5591
5592 if (errmsg == NULL)
5593 {
5594# ifdef FEAT_KEYMAP
5595 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5596 * (with another encoding). */
5597 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5598 (void)keymap_init();
5599# endif
5600
5601 /* When 'termencoding' is not empty and 'encoding' changes or when
5602 * 'termencoding' changes, need to setup for keyboard input and
5603 * display output conversion. */
5604 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5605 {
5606 convert_setup(&input_conv, p_tenc, p_enc);
5607 convert_setup(&output_conv, p_enc, p_tenc);
5608 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005609
5610# if defined(WIN3264) && defined(FEAT_MBYTE)
5611 /* $HOME may have characters in active code page. */
5612 if (varp == &p_enc)
5613 init_homedir();
5614# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615 }
5616 }
5617#endif
5618
5619#if defined(FEAT_POSTSCRIPT)
5620 else if (varp == &p_penc)
5621 {
5622 /* Canonize printencoding if VIM standard one */
5623 p = enc_canonize(p_penc);
5624 if (p != NULL)
5625 {
5626 vim_free(p_penc);
5627 p_penc = p;
5628 }
5629 else
5630 {
5631 /* Ensure lower case and '-' for '_' */
5632 for (s = p_penc; *s != NUL; s++)
5633 {
5634 if (*s == '_')
5635 *s = '-';
5636 else
5637 *s = TOLOWER_ASC(*s);
5638 }
5639 }
5640 }
5641#endif
5642
Bram Moolenaar9372a112005-12-06 19:59:18 +00005643#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644 else if (varp == &p_imak)
5645 {
5646 if (gui.in_use && !im_xim_isvalid_imactivate())
5647 errmsg = e_invarg;
5648 }
5649#endif
5650
5651#ifdef FEAT_KEYMAP
5652 else if (varp == &curbuf->b_p_keymap)
5653 {
5654 /* load or unload key mapping tables */
5655 errmsg = keymap_init();
5656
5657 /* When successfully installed a new keymap switch on using it. */
5658 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5659 {
5660 curbuf->b_p_iminsert = B_IMODE_LMAP;
5661 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5662 curbuf->b_p_imsearch = B_IMODE_LMAP;
5663 set_iminsert_global();
5664 set_imsearch_global();
5665# ifdef FEAT_WINDOWS
5666 status_redraw_curbuf();
5667# endif
5668 }
5669 }
5670#endif
5671
5672 /* 'fileformat' */
5673 else if (gvarp == &p_ff)
5674 {
5675 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5676 errmsg = e_modifiable;
5677 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5678 errmsg = e_invarg;
5679 else
5680 {
5681 /* may also change 'textmode' */
5682 if (get_fileformat(curbuf) == EOL_DOS)
5683 curbuf->b_p_tx = TRUE;
5684 else
5685 curbuf->b_p_tx = FALSE;
5686#ifdef FEAT_TITLE
5687 need_maketitle = TRUE;
5688#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005689 /* update flag in swap file */
5690 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 }
5692 }
5693
5694 /* 'fileformats' */
5695 else if (varp == &p_ffs)
5696 {
5697 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5698 errmsg = e_invarg;
5699 else
5700 {
5701 /* also change 'textauto' */
5702 if (*p_ffs == NUL)
5703 p_ta = FALSE;
5704 else
5705 p_ta = TRUE;
5706 }
5707 }
5708
5709#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5710 /* 'cryptkey' */
5711 else if (gvarp == &p_key)
5712 {
5713 /* Make sure the ":set" command doesn't show the new value in the
5714 * history. */
5715 remove_key_from_history();
5716 }
5717#endif
5718
5719 /* 'matchpairs' */
5720 else if (gvarp == &p_mps)
5721 {
5722 /* Check for "x:y,x:y" */
5723 for (p = *varp; *p != NUL; p += 4)
5724 {
5725 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5726 {
5727 errmsg = e_invarg;
5728 break;
5729 }
5730 if (p[3] == NUL)
5731 break;
5732 }
5733 }
5734
5735#ifdef FEAT_COMMENTS
5736 /* 'comments' */
5737 else if (gvarp == &p_com)
5738 {
5739 for (s = *varp; *s; )
5740 {
5741 while (*s && *s != ':')
5742 {
5743 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5744 && !VIM_ISDIGIT(*s) && *s != '-')
5745 {
5746 errmsg = illegal_char(errbuf, *s);
5747 break;
5748 }
5749 ++s;
5750 }
5751 if (*s++ == NUL)
5752 errmsg = (char_u *)N_("E524: Missing colon");
5753 else if (*s == ',' || *s == NUL)
5754 errmsg = (char_u *)N_("E525: Zero length string");
5755 if (errmsg != NULL)
5756 break;
5757 while (*s && *s != ',')
5758 {
5759 if (*s == '\\' && s[1] != NUL)
5760 ++s;
5761 ++s;
5762 }
5763 s = skip_to_option_part(s);
5764 }
5765 }
5766#endif
5767
5768 /* 'listchars' */
5769 else if (varp == &p_lcs)
5770 {
5771 errmsg = set_chars_option(varp);
5772 }
5773
5774#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5775 /* 'fillchars' */
5776 else if (varp == &p_fcs)
5777 {
5778 errmsg = set_chars_option(varp);
5779 }
5780#endif
5781
5782#ifdef FEAT_CMDWIN
5783 /* 'cedit' */
5784 else if (varp == &p_cedit)
5785 {
5786 errmsg = check_cedit();
5787 }
5788#endif
5789
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005790 /* 'verbosefile' */
5791 else if (varp == &p_vfile)
5792 {
5793 verbose_stop();
5794 if (*p_vfile != NUL && verbose_open() == FAIL)
5795 errmsg = e_invarg;
5796 }
5797
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798#ifdef FEAT_VIMINFO
5799 /* 'viminfo' */
5800 else if (varp == &p_viminfo)
5801 {
5802 for (s = p_viminfo; *s;)
5803 {
5804 /* Check it's a valid character */
5805 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5806 {
5807 errmsg = illegal_char(errbuf, *s);
5808 break;
5809 }
5810 if (*s == 'n') /* name is always last one */
5811 {
5812 break;
5813 }
5814 else if (*s == 'r') /* skip until next ',' */
5815 {
5816 while (*++s && *s != ',')
5817 ;
5818 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005819 else if (*s == '%')
5820 {
5821 /* optional number */
5822 while (vim_isdigit(*++s))
5823 ;
5824 }
5825 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826 ++s; /* no extra chars */
5827 else /* must have a number */
5828 {
5829 while (vim_isdigit(*++s))
5830 ;
5831
5832 if (!VIM_ISDIGIT(*(s - 1)))
5833 {
5834 if (errbuf != NULL)
5835 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005836 sprintf((char *)errbuf,
5837 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838 transchar_byte(*(s - 1)));
5839 errmsg = errbuf;
5840 }
5841 else
5842 errmsg = (char_u *)"";
5843 break;
5844 }
5845 }
5846 if (*s == ',')
5847 ++s;
5848 else if (*s)
5849 {
5850 if (errbuf != NULL)
5851 errmsg = (char_u *)N_("E527: Missing comma");
5852 else
5853 errmsg = (char_u *)"";
5854 break;
5855 }
5856 }
5857 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5858 errmsg = (char_u *)N_("E528: Must specify a ' value");
5859 }
5860#endif /* FEAT_VIMINFO */
5861
5862 /* terminal options */
5863 else if (istermoption(&options[opt_idx]) && full_screen)
5864 {
5865 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5866 if (varp == &T_CCO)
5867 {
5868 t_colors = atoi((char *)T_CCO);
5869 if (t_colors <= 1)
5870 {
5871 if (new_value_alloced)
5872 vim_free(T_CCO);
5873 T_CCO = empty_option;
5874 }
5875 /* We now have a different color setup, initialize it again. */
5876 init_highlight(TRUE, FALSE);
5877 }
5878 ttest(FALSE);
5879 if (varp == &T_ME)
5880 {
5881 out_str(T_ME);
5882 redraw_later(CLEAR);
5883#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5884 /* Since t_me has been set, this probably means that the user
5885 * wants to use this as default colors. Need to reset default
5886 * background/foreground colors. */
5887 mch_set_normal_colors();
5888#endif
5889 }
5890 }
5891
5892#ifdef FEAT_LINEBREAK
5893 /* 'showbreak' */
5894 else if (varp == &p_sbr)
5895 {
5896 for (s = p_sbr; *s; )
5897 {
5898 if (ptr2cells(s) != 1)
5899 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005900 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 }
5902 }
5903#endif
5904
5905#ifdef FEAT_GUI
5906 /* 'guifont' */
5907 else if (varp == &p_guifont)
5908 {
5909 if (gui.in_use)
5910 {
5911 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005912# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 /*
5914 * Put up a font dialog and let the user select a new value.
5915 * If this is cancelled go back to the old value but don't
5916 * give an error message.
5917 */
5918 if (STRCMP(p, "*") == 0)
5919 {
5920 p = gui_mch_font_dialog(oldval);
5921
5922 if (new_value_alloced)
5923 free_string_option(p_guifont);
5924
5925 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5926 new_value_alloced = TRUE;
5927 }
5928# endif
5929 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5930 {
5931# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5932 if (STRCMP(p_guifont, "*") == 0)
5933 {
5934 /* Dialog was cancelled: Keep the old value without giving
5935 * an error message. */
5936 if (new_value_alloced)
5937 free_string_option(p_guifont);
5938 p_guifont = vim_strsave(oldval);
5939 new_value_alloced = TRUE;
5940 }
5941 else
5942# endif
5943 errmsg = (char_u *)N_("E596: Invalid font(s)");
5944 }
5945 }
5946 }
5947# ifdef FEAT_XFONTSET
5948 else if (varp == &p_guifontset)
5949 {
5950 if (STRCMP(p_guifontset, "*") == 0)
5951 errmsg = (char_u *)N_("E597: can't select fontset");
5952 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5953 errmsg = (char_u *)N_("E598: Invalid fontset");
5954 }
5955# endif
5956# ifdef FEAT_MBYTE
5957 else if (varp == &p_guifontwide)
5958 {
5959 if (STRCMP(p_guifontwide, "*") == 0)
5960 errmsg = (char_u *)N_("E533: can't select wide font");
5961 else if (gui_get_wide_font() == FAIL)
5962 errmsg = (char_u *)N_("E534: Invalid wide font");
5963 }
5964# endif
5965#endif
5966
5967#ifdef CURSOR_SHAPE
5968 /* 'guicursor' */
5969 else if (varp == &p_guicursor)
5970 errmsg = parse_shape_opt(SHAPE_CURSOR);
5971#endif
5972
5973#ifdef FEAT_MOUSESHAPE
5974 /* 'mouseshape' */
5975 else if (varp == &p_mouseshape)
5976 {
5977 errmsg = parse_shape_opt(SHAPE_MOUSE);
5978 update_mouseshape(-1);
5979 }
5980#endif
5981
5982#ifdef FEAT_PRINTER
5983 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005984 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005985# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005986 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005987 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005988# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989#endif
5990
5991#ifdef FEAT_LANGMAP
5992 /* 'langmap' */
5993 else if (varp == &p_langmap)
5994 langmap_set();
5995#endif
5996
5997#ifdef FEAT_LINEBREAK
5998 /* 'breakat' */
5999 else if (varp == &p_breakat)
6000 fill_breakat_flags();
6001#endif
6002
6003#ifdef FEAT_TITLE
6004 /* 'titlestring' and 'iconstring' */
6005 else if (varp == &p_titlestring || varp == &p_iconstring)
6006 {
6007# ifdef FEAT_STL_OPT
6008 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6009
6010 /* NULL => statusline syntax */
6011 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6012 stl_syntax |= flagval;
6013 else
6014 stl_syntax &= ~flagval;
6015# endif
6016 did_set_title(varp == &p_iconstring);
6017
6018 }
6019#endif
6020
6021#ifdef FEAT_GUI
6022 /* 'guioptions' */
6023 else if (varp == &p_go)
6024 gui_init_which_components(oldval);
6025#endif
6026
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006027#if defined(FEAT_GUI_TABLINE)
6028 /* 'guitablabel' */
6029 else if (varp == &p_gtl)
6030 gui_update_tabline();
6031#endif
6032
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6034 /* 'ttymouse' */
6035 else if (varp == &p_ttym)
6036 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006037 /* Switch the mouse off before changing the escape sequences used for
6038 * that. */
6039 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6041 errmsg = e_invarg;
6042 else
6043 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006044 if (termcap_active)
6045 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046 }
6047#endif
6048
6049#ifdef FEAT_VISUAL
6050 /* 'selection' */
6051 else if (varp == &p_sel)
6052 {
6053 if (*p_sel == NUL
6054 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6055 errmsg = e_invarg;
6056 }
6057
6058 /* 'selectmode' */
6059 else if (varp == &p_slm)
6060 {
6061 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6062 errmsg = e_invarg;
6063 }
6064#endif
6065
6066#ifdef FEAT_BROWSE
6067 /* 'browsedir' */
6068 else if (varp == &p_bsdir)
6069 {
6070 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6071 && !mch_isdir(p_bsdir))
6072 errmsg = e_invarg;
6073 }
6074#endif
6075
6076#ifdef FEAT_VISUAL
6077 /* 'keymodel' */
6078 else if (varp == &p_km)
6079 {
6080 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6081 errmsg = e_invarg;
6082 else
6083 {
6084 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6085 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6086 }
6087 }
6088#endif
6089
6090 /* 'mousemodel' */
6091 else if (varp == &p_mousem)
6092 {
6093 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6094 errmsg = e_invarg;
6095#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6096 else if (*p_mousem != *oldval)
6097 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6098 * to create or delete the popup menus. */
6099 gui_motif_update_mousemodel(root_menu);
6100#endif
6101 }
6102
6103 /* 'switchbuf' */
6104 else if (varp == &p_swb)
6105 {
6106 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
6107 errmsg = e_invarg;
6108 }
6109
6110 /* 'debug' */
6111 else if (varp == &p_debug)
6112 {
6113 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
6114 errmsg = e_invarg;
6115 }
6116
6117 /* 'display' */
6118 else if (varp == &p_dy)
6119 {
6120 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6121 errmsg = e_invarg;
6122 else
6123 (void)init_chartab();
6124
6125 }
6126
6127#ifdef FEAT_VERTSPLIT
6128 /* 'eadirection' */
6129 else if (varp == &p_ead)
6130 {
6131 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6132 errmsg = e_invarg;
6133 }
6134#endif
6135
6136#ifdef FEAT_CLIPBOARD
6137 /* 'clipboard' */
6138 else if (varp == &p_cb)
6139 errmsg = check_clipboard_option();
6140#endif
6141
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006142#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006143 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6144 * buffer in which 'spell' is set load the wordlists. */
6145 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006146 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006147 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006148 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006149
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006150 if (varp == &(curbuf->b_p_spf))
6151 {
6152 l = STRLEN(curbuf->b_p_spf);
6153 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6154 ".add") != 0))
6155 errmsg = e_invarg;
6156 }
6157
6158 if (errmsg == NULL)
6159 {
6160 FOR_ALL_WINDOWS(wp)
6161 if (wp->w_buffer == curbuf && wp->w_p_spell)
6162 {
6163 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006164# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006165 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006166# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006167 }
6168 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006169 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006170 /* When 'spellcapcheck' is set compile the regexp program. */
6171 else if (varp == &(curbuf->b_p_spc))
6172 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006173 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006174 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006175 /* 'spellsuggest' */
6176 else if (varp == &p_sps)
6177 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006178 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006179 errmsg = e_invarg;
6180 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006181 /* 'mkspellmem' */
6182 else if (varp == &p_msm)
6183 {
6184 if (spell_check_msm() != OK)
6185 errmsg = e_invarg;
6186 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006187#endif
6188
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189#ifdef FEAT_QUICKFIX
6190 /* When 'bufhidden' is set, check for valid value. */
6191 else if (gvarp == &p_bh)
6192 {
6193 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6194 errmsg = e_invarg;
6195 }
6196
6197 /* When 'buftype' is set, check for valid value. */
6198 else if (gvarp == &p_bt)
6199 {
6200 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6201 errmsg = e_invarg;
6202 else
6203 {
6204# ifdef FEAT_WINDOWS
6205 if (curwin->w_status_height)
6206 {
6207 curwin->w_redr_status = TRUE;
6208 redraw_later(VALID);
6209 }
6210# endif
6211 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6212 }
6213 }
6214#endif
6215
6216#ifdef FEAT_STL_OPT
6217 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006218 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219 {
6220 int wid;
6221
6222 if (varp == &p_ruf) /* reset ru_wid first */
6223 ru_wid = 0;
6224 s = *varp;
6225 if (varp == &p_ruf && *s == '%')
6226 {
6227 /* set ru_wid if 'ruf' starts with "%99(" */
6228 if (*++s == '-') /* ignore a '-' */
6229 s++;
6230 wid = getdigits(&s);
6231 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6232 ru_wid = wid;
6233 else
6234 errmsg = check_stl_option(p_ruf);
6235 }
6236 else
6237 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006238 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006239 comp_col();
6240 }
6241#endif
6242
6243#ifdef FEAT_INS_EXPAND
6244 /* check if it is a valid value for 'complete' -- Acevedo */
6245 else if (gvarp == &p_cpt)
6246 {
6247 for (s = *varp; *s;)
6248 {
6249 while(*s == ',' || *s == ' ')
6250 s++;
6251 if (!*s)
6252 break;
6253 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6254 {
6255 errmsg = illegal_char(errbuf, *s);
6256 break;
6257 }
6258 if (*++s != NUL && *s != ',' && *s != ' ')
6259 {
6260 if (s[-1] == 'k' || s[-1] == 's')
6261 {
6262 /* skip optional filename after 'k' and 's' */
6263 while (*s && *s != ',' && *s != ' ')
6264 {
6265 if (*s == '\\')
6266 ++s;
6267 ++s;
6268 }
6269 }
6270 else
6271 {
6272 if (errbuf != NULL)
6273 {
6274 sprintf((char *)errbuf,
6275 _("E535: Illegal character after <%c>"),
6276 *--s);
6277 errmsg = errbuf;
6278 }
6279 else
6280 errmsg = (char_u *)"";
6281 break;
6282 }
6283 }
6284 }
6285 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006286
6287 /* 'completeopt' */
6288 else if (varp == &p_cot)
6289 {
6290 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6291 errmsg = e_invarg;
6292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293#endif /* FEAT_INS_EXPAND */
6294
6295
6296#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6297 else if (varp == &p_toolbar)
6298 {
6299 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6300 &toolbar_flags, TRUE) != OK)
6301 errmsg = e_invarg;
6302 else
6303 {
6304 out_flush();
6305 gui_mch_show_toolbar((toolbar_flags &
6306 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6307 }
6308 }
6309#endif
6310
6311#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6312 /* 'toolbariconsize': GTK+ 2 only */
6313 else if (varp == &p_tbis)
6314 {
6315 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6316 errmsg = e_invarg;
6317 else
6318 {
6319 out_flush();
6320 gui_mch_show_toolbar((toolbar_flags &
6321 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6322 }
6323 }
6324#endif
6325
6326 /* 'pastetoggle': translate key codes like in a mapping */
6327 else if (varp == &p_pt)
6328 {
6329 if (*p_pt)
6330 {
6331 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6332 if (p != NULL)
6333 {
6334 if (new_value_alloced)
6335 free_string_option(p_pt);
6336 p_pt = p;
6337 new_value_alloced = TRUE;
6338 }
6339 }
6340 }
6341
6342 /* 'backspace' */
6343 else if (varp == &p_bs)
6344 {
6345 if (VIM_ISDIGIT(*p_bs))
6346 {
6347 if (*p_bs >'2' || p_bs[1] != NUL)
6348 errmsg = e_invarg;
6349 }
6350 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6351 errmsg = e_invarg;
6352 }
6353
6354 /* 'casemap' */
6355 else if (varp == &p_cmp)
6356 {
6357 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6358 errmsg = e_invarg;
6359 }
6360
6361#ifdef FEAT_DIFF
6362 /* 'diffopt' */
6363 else if (varp == &p_dip)
6364 {
6365 if (diffopt_changed() == FAIL)
6366 errmsg = e_invarg;
6367 }
6368#endif
6369
6370#ifdef FEAT_FOLDING
6371 /* 'foldmethod' */
6372 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6373 {
6374 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6375 || *curwin->w_p_fdm == NUL)
6376 errmsg = e_invarg;
6377 else
6378 foldUpdateAll(curwin);
6379 }
6380# ifdef FEAT_EVAL
6381 /* 'foldexpr' */
6382 else if (varp == &curwin->w_p_fde)
6383 {
6384 if (foldmethodIsExpr(curwin))
6385 foldUpdateAll(curwin);
6386 }
6387# endif
6388 /* 'foldmarker' */
6389 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6390 {
6391 p = vim_strchr(*varp, ',');
6392 if (p == NULL)
6393 errmsg = (char_u *)N_("E536: comma required");
6394 else if (p == *varp || p[1] == NUL)
6395 errmsg = e_invarg;
6396 else if (foldmethodIsMarker(curwin))
6397 foldUpdateAll(curwin);
6398 }
6399 /* 'commentstring' */
6400 else if (gvarp == &p_cms)
6401 {
6402 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6403 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6404 }
6405 /* 'foldopen' */
6406 else if (varp == &p_fdo)
6407 {
6408 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6409 errmsg = e_invarg;
6410 }
6411 /* 'foldclose' */
6412 else if (varp == &p_fcl)
6413 {
6414 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6415 errmsg = e_invarg;
6416 }
6417#endif
6418
6419#ifdef FEAT_VIRTUALEDIT
6420 /* 'virtualedit' */
6421 else if (varp == &p_ve)
6422 {
6423 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6424 errmsg = e_invarg;
6425 else if (STRCMP(p_ve, oldval) != 0)
6426 {
6427 /* Recompute cursor position in case the new 've' setting
6428 * changes something. */
6429 validate_virtcol();
6430 coladvance(curwin->w_virtcol);
6431 }
6432 }
6433#endif
6434
6435#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6436 else if (varp == &p_csqf)
6437 {
6438 if (p_csqf != NULL)
6439 {
6440 p = p_csqf;
6441 while (*p != NUL)
6442 {
6443 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6444 || p[1] == NUL
6445 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6446 || (p[2] != NUL && p[2] != ','))
6447 {
6448 errmsg = e_invarg;
6449 break;
6450 }
6451 else if (p[2] == NUL)
6452 break;
6453 else
6454 p += 3;
6455 }
6456 }
6457 }
6458#endif
6459
6460 /* Options that are a list of flags. */
6461 else
6462 {
6463 p = NULL;
6464 if (varp == &p_ww)
6465 p = (char_u *)WW_ALL;
6466 if (varp == &p_shm)
6467 p = (char_u *)SHM_ALL;
6468 else if (varp == &(p_cpo))
6469 p = (char_u *)CPO_ALL;
6470 else if (varp == &(curbuf->b_p_fo))
6471 p = (char_u *)FO_ALL;
6472 else if (varp == &p_mouse)
6473 {
6474#ifdef FEAT_MOUSE
6475 p = (char_u *)MOUSE_ALL;
6476#else
6477 if (*p_mouse != NUL)
6478 errmsg = (char_u *)N_("E538: No mouse support");
6479#endif
6480 }
6481#if defined(FEAT_GUI)
6482 else if (varp == &p_go)
6483 p = (char_u *)GO_ALL;
6484#endif
6485 if (p != NULL)
6486 {
6487 for (s = *varp; *s; ++s)
6488 if (vim_strchr(p, *s) == NULL)
6489 {
6490 errmsg = illegal_char(errbuf, *s);
6491 break;
6492 }
6493 }
6494 }
6495
6496 /*
6497 * If error detected, restore the previous value.
6498 */
6499 if (errmsg != NULL)
6500 {
6501 if (new_value_alloced)
6502 free_string_option(*varp);
6503 *varp = oldval;
6504 /*
6505 * When resetting some values, need to act on it.
6506 */
6507 if (did_chartab)
6508 (void)init_chartab();
6509 if (varp == &p_hl)
6510 (void)highlight_changed();
6511 }
6512 else
6513 {
6514#ifdef FEAT_EVAL
6515 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006516 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006517#endif
6518 /*
6519 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006520 * Use "free_oldval", because recursiveness may change the flags under
6521 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006523 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006524 free_string_option(oldval);
6525 if (new_value_alloced)
6526 options[opt_idx].flags |= P_ALLOCED;
6527 else
6528 options[opt_idx].flags &= ~P_ALLOCED;
6529
6530 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006531 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532 {
6533 /* global option with local value set to use global value; free
6534 * the local value and make it empty */
6535 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6536 free_string_option(*(char_u **)p);
6537 *(char_u **)p = empty_option;
6538 }
6539
6540 /* May set global value for local option. */
6541 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6542 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006543
6544#ifdef FEAT_AUTOCMD
6545 /*
6546 * Trigger the autocommand only after setting the flags.
6547 */
6548# ifdef FEAT_SYN_HL
6549 /* When 'syntax' is set, load the syntax of that name */
6550 if (varp == &(curbuf->b_p_syn))
6551 {
6552 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6553 curbuf->b_fname, TRUE, curbuf);
6554 }
6555# endif
6556 else if (varp == &(curbuf->b_p_ft))
6557 {
6558 /* 'filetype' is set, trigger the FileType autocommand */
6559 did_filetype = TRUE;
6560 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6561 curbuf->b_fname, TRUE, curbuf);
6562 }
6563#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006564#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006565 if (varp == &(curbuf->b_p_spl))
6566 {
6567 char_u fname[200];
6568
6569 /*
6570 * Source the spell/LANG.vim in 'runtimepath'.
6571 * They could set 'spellcapcheck' depending on the language.
6572 * Use the first name in 'spelllang' up to '_region' or
6573 * '.encoding'.
6574 */
6575 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6576 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6577 break;
6578 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6579 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6580 source_runtime(fname, TRUE);
6581 }
6582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006583 }
6584
6585#ifdef FEAT_MOUSE
6586 if (varp == &p_mouse)
6587 {
6588# ifdef FEAT_MOUSE_TTY
6589 if (*p_mouse == NUL)
6590 mch_setmouse(FALSE); /* switch mouse off */
6591 else
6592# endif
6593 setmouse(); /* in case 'mouse' changed */
6594 }
6595#endif
6596
6597 if (curwin->w_curswant != MAXCOL)
6598 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6599 check_redraw(options[opt_idx].flags);
6600
6601 return errmsg;
6602}
6603
6604/*
6605 * Handle setting 'listchars' or 'fillchars'.
6606 * Returns error message, NULL if it's OK.
6607 */
6608 static char_u *
6609set_chars_option(varp)
6610 char_u **varp;
6611{
6612 int round, i, len, entries;
6613 char_u *p, *s;
6614 int c1, c2 = 0;
6615 struct charstab
6616 {
6617 int *cp;
6618 char *name;
6619 };
6620#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6621 static struct charstab filltab[] =
6622 {
6623 {&fill_stl, "stl"},
6624 {&fill_stlnc, "stlnc"},
6625 {&fill_vert, "vert"},
6626 {&fill_fold, "fold"},
6627 {&fill_diff, "diff"},
6628 };
6629#endif
6630 static struct charstab lcstab[] =
6631 {
6632 {&lcs_eol, "eol"},
6633 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006634 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 {&lcs_prec, "precedes"},
6636 {&lcs_tab2, "tab"},
6637 {&lcs_trail, "trail"},
6638 };
6639 struct charstab *tab;
6640
6641#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6642 if (varp == &p_lcs)
6643#endif
6644 {
6645 tab = lcstab;
6646 entries = sizeof(lcstab) / sizeof(struct charstab);
6647 }
6648#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6649 else
6650 {
6651 tab = filltab;
6652 entries = sizeof(filltab) / sizeof(struct charstab);
6653 }
6654#endif
6655
6656 /* first round: check for valid value, second round: assign values */
6657 for (round = 0; round <= 1; ++round)
6658 {
6659 if (round)
6660 {
6661 /* After checking that the value is valid: set defaults: space for
6662 * 'fillchars', NUL for 'listchars' */
6663 for (i = 0; i < entries; ++i)
6664 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6665 if (varp == &p_lcs)
6666 lcs_tab1 = NUL;
6667#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6668 else
6669 fill_diff = '-';
6670#endif
6671 }
6672 p = *varp;
6673 while (*p)
6674 {
6675 for (i = 0; i < entries; ++i)
6676 {
6677 len = (int)STRLEN(tab[i].name);
6678 if (STRNCMP(p, tab[i].name, len) == 0
6679 && p[len] == ':'
6680 && p[len + 1] != NUL)
6681 {
6682 s = p + len + 1;
6683#ifdef FEAT_MBYTE
6684 c1 = mb_ptr2char_adv(&s);
6685#else
6686 c1 = *s++;
6687#endif
6688 if (tab[i].cp == &lcs_tab2)
6689 {
6690 if (*s == NUL)
6691 continue;
6692#ifdef FEAT_MBYTE
6693 c2 = mb_ptr2char_adv(&s);
6694#else
6695 c2 = *s++;
6696#endif
6697 }
6698 if (*s == ',' || *s == NUL)
6699 {
6700 if (round)
6701 {
6702 if (tab[i].cp == &lcs_tab2)
6703 {
6704 lcs_tab1 = c1;
6705 lcs_tab2 = c2;
6706 }
6707 else
6708 *(tab[i].cp) = c1;
6709
6710 }
6711 p = s;
6712 break;
6713 }
6714 }
6715 }
6716
6717 if (i == entries)
6718 return e_invarg;
6719 if (*p == ',')
6720 ++p;
6721 }
6722 }
6723
6724 return NULL; /* no error */
6725}
6726
6727#ifdef FEAT_STL_OPT
6728/*
6729 * Check validity of options with the 'statusline' format.
6730 * Return error message or NULL.
6731 */
6732 char_u *
6733check_stl_option(s)
6734 char_u *s;
6735{
6736 int itemcnt = 0;
6737 int groupdepth = 0;
6738 static char_u errbuf[80];
6739
6740 while (*s && itemcnt < STL_MAX_ITEM)
6741 {
6742 /* Check for valid keys after % sequences */
6743 while (*s && *s != '%')
6744 s++;
6745 if (!*s)
6746 break;
6747 s++;
6748 if (*s != '%' && *s != ')')
6749 ++itemcnt;
6750 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6751 {
6752 s++;
6753 continue;
6754 }
6755 if (*s == ')')
6756 {
6757 s++;
6758 if (--groupdepth < 0)
6759 break;
6760 continue;
6761 }
6762 if (*s == '-')
6763 s++;
6764 while (VIM_ISDIGIT(*s))
6765 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006766 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 continue;
6768 if (*s == '.')
6769 {
6770 s++;
6771 while (*s && VIM_ISDIGIT(*s))
6772 s++;
6773 }
6774 if (*s == '(')
6775 {
6776 groupdepth++;
6777 continue;
6778 }
6779 if (vim_strchr(STL_ALL, *s) == NULL)
6780 {
6781 return illegal_char(errbuf, *s);
6782 }
6783 if (*s == '{')
6784 {
6785 s++;
6786 while (*s != '}' && *s)
6787 s++;
6788 if (*s != '}')
6789 return (char_u *)N_("E540: Unclosed expression sequence");
6790 }
6791 }
6792 if (itemcnt >= STL_MAX_ITEM)
6793 return (char_u *)N_("E541: too many items");
6794 if (groupdepth != 0)
6795 return (char_u *)N_("E542: unbalanced groups");
6796 return NULL;
6797}
6798#endif
6799
6800#ifdef FEAT_CLIPBOARD
6801/*
6802 * Extract the items in the 'clipboard' option and set global values.
6803 */
6804 static char_u *
6805check_clipboard_option()
6806{
6807 int new_unnamed = FALSE;
6808 int new_autoselect = FALSE;
6809 int new_autoselectml = FALSE;
6810 regprog_T *new_exclude_prog = NULL;
6811 char_u *errmsg = NULL;
6812 char_u *p;
6813
6814 for (p = p_cb; *p != NUL; )
6815 {
6816 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6817 {
6818 new_unnamed = TRUE;
6819 p += 7;
6820 }
6821 else if (STRNCMP(p, "autoselect", 10) == 0
6822 && (p[10] == ',' || p[10] == NUL))
6823 {
6824 new_autoselect = TRUE;
6825 p += 10;
6826 }
6827 else if (STRNCMP(p, "autoselectml", 12) == 0
6828 && (p[12] == ',' || p[12] == NUL))
6829 {
6830 new_autoselectml = TRUE;
6831 p += 12;
6832 }
6833 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6834 {
6835 p += 8;
6836 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6837 if (new_exclude_prog == NULL)
6838 errmsg = e_invarg;
6839 break;
6840 }
6841 else
6842 {
6843 errmsg = e_invarg;
6844 break;
6845 }
6846 if (*p == ',')
6847 ++p;
6848 }
6849 if (errmsg == NULL)
6850 {
6851 clip_unnamed = new_unnamed;
6852 clip_autoselect = new_autoselect;
6853 clip_autoselectml = new_autoselectml;
6854 vim_free(clip_exclude_prog);
6855 clip_exclude_prog = new_exclude_prog;
6856 }
6857 else
6858 vim_free(new_exclude_prog);
6859
6860 return errmsg;
6861}
6862#endif
6863
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006864#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006865/*
6866 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6867 * Return error message when failed, NULL when OK.
6868 */
6869 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006870compile_cap_prog(buf)
6871 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006872{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006873 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006874 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006875
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006876 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006877 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006878 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006879 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006880 /* Prepend a ^ so that we only match at one column */
6881 re = concat_str((char_u *)"^", buf->b_p_spc);
6882 if (re != NULL)
6883 {
6884 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6885 if (buf->b_cap_prog == NULL)
6886 {
6887 buf->b_cap_prog = rp; /* restore the previous program */
6888 return e_invarg;
6889 }
6890 vim_free(re);
6891 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006892 }
6893
6894 vim_free(rp);
6895 return NULL;
6896}
6897#endif
6898
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006899#if defined(FEAT_EVAL) || defined(PROTO)
6900/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006901 * Set the scriptID for an option, taking care of setting the buffer- or
6902 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006903 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006904 static void
6905set_option_scriptID_idx(opt_idx, opt_flags, id)
6906 int opt_idx;
6907 int opt_flags;
6908 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006909{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006910 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
6911 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006912
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006913 /* Remember where the option was set. For local options need to do that
6914 * in the buffer or window structure. */
6915 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006916 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006917 if (both || (opt_flags & OPT_LOCAL))
6918 {
6919 if (indir & PV_BUF)
6920 curbuf->b_p_scriptID[indir & PV_MASK] = id;
6921 else if (indir & PV_WIN)
6922 curwin->w_p_scriptID[indir & PV_MASK] = id;
6923 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006924}
6925#endif
6926
Bram Moolenaar071d4272004-06-13 20:20:40 +00006927/*
6928 * Set the value of a boolean option, and take care of side effects.
6929 * Returns NULL for success, or an error message for an error.
6930 */
6931 static char_u *
6932set_bool_option(opt_idx, varp, value, opt_flags)
6933 int opt_idx; /* index in options[] table */
6934 char_u *varp; /* pointer to the option variable */
6935 int value; /* new value */
6936 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6937{
6938 int old_value = *(int *)varp;
6939
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940 /* Disallow changing some options from secure mode */
6941 if ((secure
6942#ifdef HAVE_SANDBOX
6943 || sandbox != 0
6944#endif
6945 ) && (options[opt_idx].flags & P_SECURE))
6946 return e_secure;
6947
6948 *(int *)varp = value; /* set the new value */
6949#ifdef FEAT_EVAL
6950 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006951 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952#endif
6953
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006954#ifdef FEAT_GUI
6955 need_mouse_correct = TRUE;
6956#endif
6957
Bram Moolenaar071d4272004-06-13 20:20:40 +00006958 /* May set global value for local option. */
6959 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6960 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6961
6962 /*
6963 * Handle side effects of changing a bool option.
6964 */
6965
6966 /* 'compatible' */
6967 if ((int *)varp == &p_cp)
6968 {
6969 compatible_set();
6970 }
6971
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 else if ((int *)varp == &curbuf->b_p_ro)
6973 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006974 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6976 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006977
6978 /* when 'readonly' is set may give W10 again */
6979 if (curbuf->b_p_ro)
6980 curbuf->b_did_warn = FALSE;
6981
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982#ifdef FEAT_TITLE
6983 need_maketitle = TRUE;
6984#endif
6985 }
6986
6987#ifdef FEAT_TITLE
6988 /* when 'modifiable' is changed, redraw the window title */
6989 else if ((int *)varp == &curbuf->b_p_ma)
6990 need_maketitle = TRUE;
6991 /* when 'endofline' is changed, redraw the window title */
6992 else if ((int *)varp == &curbuf->b_p_eol)
6993 need_maketitle = TRUE;
6994#endif
6995
6996 /* when 'bin' is set also set some other options */
6997 else if ((int *)varp == &curbuf->b_p_bin)
6998 {
6999 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7000#ifdef FEAT_TITLE
7001 need_maketitle = TRUE;
7002#endif
7003 }
7004
7005#ifdef FEAT_AUTOCMD
7006 /* when 'buflisted' changes, trigger autocommands */
7007 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7008 {
7009 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7010 NULL, NULL, TRUE, curbuf);
7011 }
7012#endif
7013
7014 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7015 else if ((int *)varp == &curbuf->b_p_swf)
7016 {
7017 if (curbuf->b_p_swf && p_uc)
7018 ml_open_file(curbuf); /* create the swap file */
7019 else
7020 mf_close_file(curbuf, TRUE); /* remove the swap file */
7021 }
7022
7023 /* when 'terse' is set change 'shortmess' */
7024 else if ((int *)varp == &p_terse)
7025 {
7026 char_u *p;
7027
7028 p = vim_strchr(p_shm, SHM_SEARCH);
7029
7030 /* insert 's' in p_shm */
7031 if (p_terse && p == NULL)
7032 {
7033 STRCPY(IObuff, p_shm);
7034 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007035 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 }
7037 /* remove 's' from p_shm */
7038 else if (!p_terse && p != NULL)
7039 mch_memmove(p, p + 1, STRLEN(p));
7040 }
7041
7042 /* when 'paste' is set or reset also change other options */
7043 else if ((int *)varp == &p_paste)
7044 {
7045 paste_option_changed();
7046 }
7047
7048 /* when 'insertmode' is set from an autocommand need to do work here */
7049 else if ((int *)varp == &p_im)
7050 {
7051 if (p_im)
7052 {
7053 if ((State & INSERT) == 0)
7054 need_start_insertmode = TRUE;
7055 stop_insert_mode = FALSE;
7056 }
7057 else
7058 {
7059 need_start_insertmode = FALSE;
7060 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007061 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062 clear_cmdline = TRUE; /* remove "(insert)" */
7063 restart_edit = 0;
7064 }
7065 }
7066
7067 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7068 else if ((int *)varp == &p_ic && p_hls)
7069 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007070 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 }
7072
7073#ifdef FEAT_SEARCH_EXTRA
7074 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7075 else if ((int *)varp == &p_hls)
7076 {
7077 no_hlsearch = FALSE;
7078 }
7079#endif
7080
7081#ifdef FEAT_SCROLLBIND
7082 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7083 * at the end of normal_cmd() */
7084 else if ((int *)varp == &curwin->w_p_scb)
7085 {
7086 if (curwin->w_p_scb)
7087 do_check_scrollbind(FALSE);
7088 }
7089#endif
7090
7091#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7092 /* There can be only one window with 'previewwindow' set. */
7093 else if ((int *)varp == &curwin->w_p_pvw)
7094 {
7095 if (curwin->w_p_pvw)
7096 {
7097 win_T *win;
7098
7099 for (win = firstwin; win != NULL; win = win->w_next)
7100 if (win->w_p_pvw && win != curwin)
7101 {
7102 curwin->w_p_pvw = FALSE;
7103 return (char_u *)N_("E590: A preview window already exists");
7104 }
7105 }
7106 }
7107#endif
7108
7109 /* when 'textmode' is set or reset also change 'fileformat' */
7110 else if ((int *)varp == &curbuf->b_p_tx)
7111 {
7112 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7113 }
7114
7115 /* when 'textauto' is set or reset also change 'fileformats' */
7116 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 set_string_option_direct((char_u *)"ffs", -1,
7118 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007119 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120
7121 /*
7122 * When 'lisp' option changes include/exclude '-' in
7123 * keyword characters.
7124 */
7125#ifdef FEAT_LISP
7126 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7127 {
7128 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7129 }
7130#endif
7131
7132#ifdef FEAT_TITLE
7133 /* when 'title' changed, may need to change the title; same for 'icon' */
7134 else if ((int *)varp == &p_title)
7135 {
7136 did_set_title(FALSE);
7137 }
7138
7139 else if ((int *)varp == &p_icon)
7140 {
7141 did_set_title(TRUE);
7142 }
7143#endif
7144
7145 else if ((int *)varp == &curbuf->b_changed)
7146 {
7147 if (!value)
7148 save_file_ff(curbuf); /* Buffer is unchanged */
7149#ifdef FEAT_TITLE
7150 need_maketitle = TRUE;
7151#endif
7152#ifdef FEAT_AUTOCMD
7153 modified_was_set = value;
7154#endif
7155 }
7156
7157#ifdef BACKSLASH_IN_FILENAME
7158 else if ((int *)varp == &p_ssl)
7159 {
7160 if (p_ssl)
7161 {
7162 psepc = '/';
7163 psepcN = '\\';
7164 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 }
7166 else
7167 {
7168 psepc = '\\';
7169 psepcN = '/';
7170 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171 }
7172
7173 /* need to adjust the file name arguments and buffer names. */
7174 buflist_slash_adjust();
7175 alist_slash_adjust();
7176# ifdef FEAT_EVAL
7177 scriptnames_slash_adjust();
7178# endif
7179 }
7180#endif
7181
7182 /* If 'wrap' is set, set w_leftcol to zero. */
7183 else if ((int *)varp == &curwin->w_p_wrap)
7184 {
7185 if (curwin->w_p_wrap)
7186 curwin->w_leftcol = 0;
7187 }
7188
7189#ifdef FEAT_WINDOWS
7190 else if ((int *)varp == &p_ea)
7191 {
7192 if (p_ea && !old_value)
7193 win_equal(curwin, FALSE, 0);
7194 }
7195#endif
7196
7197 else if ((int *)varp == &p_wiv)
7198 {
7199 /*
7200 * When 'weirdinvert' changed, set/reset 't_xs'.
7201 * Then set 'weirdinvert' according to value of 't_xs'.
7202 */
7203 if (p_wiv && !old_value)
7204 T_XS = (char_u *)"y";
7205 else if (!p_wiv && old_value)
7206 T_XS = empty_option;
7207 p_wiv = (*T_XS != NUL);
7208 }
7209
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007210#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007211 else if ((int *)varp == &p_beval)
7212 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213 if (p_beval == TRUE)
7214 gui_mch_enable_beval_area(balloonEval);
7215 else
7216 gui_mch_disable_beval_area(balloonEval);
7217 }
7218
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007219# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 else if ((int *)varp == &p_acd)
7221 {
7222 if (p_acd && curbuf->b_ffname != NULL
7223 && vim_chdirfile(curbuf->b_ffname) == OK)
7224 shorten_fnames(TRUE);
7225 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007226# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227#endif
7228
7229#ifdef FEAT_DIFF
7230 /* 'diff' */
7231 else if ((int *)varp == &curwin->w_p_diff)
7232 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007233 /* May add or remove the buffer from the list of diff buffers. */
7234 diff_buf_adjust(curwin);
7235# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236 if (foldmethodIsDiff(curwin))
7237 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007238# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 }
7240#endif
7241
7242#ifdef USE_IM_CONTROL
7243 /* 'imdisable' */
7244 else if ((int *)varp == &p_imdisable)
7245 {
7246 /* Only de-activate it here, it will be enabled when changing mode. */
7247 if (p_imdisable)
7248 im_set_active(FALSE);
7249 }
7250#endif
7251
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007252#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007253 /* 'spell' */
7254 else if ((int *)varp == &curwin->w_p_spell)
7255 {
7256 if (curwin->w_p_spell)
7257 {
7258 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007259
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007260 if (errmsg != NULL)
7261 EMSG(_(errmsg));
7262 }
7263 }
7264#endif
7265
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266#ifdef FEAT_FKMAP
7267 else if ((int *)varp == &p_altkeymap)
7268 {
7269 if (old_value != p_altkeymap)
7270 {
7271 if (!p_altkeymap)
7272 {
7273 p_hkmap = p_fkmap;
7274 p_fkmap = 0;
7275 }
7276 else
7277 {
7278 p_fkmap = p_hkmap;
7279 p_hkmap = 0;
7280 }
7281 (void)init_chartab();
7282 }
7283 }
7284
7285 /*
7286 * In case some second language keymapping options have changed, check
7287 * and correct the setting in a consistent way.
7288 */
7289
7290 /*
7291 * If hkmap or fkmap are set, reset Arabic keymapping.
7292 */
7293 if ((p_hkmap || p_fkmap) && p_altkeymap)
7294 {
7295 p_altkeymap = p_fkmap;
7296# ifdef FEAT_ARABIC
7297 curwin->w_p_arab = FALSE;
7298# endif
7299 (void)init_chartab();
7300 }
7301
7302 /*
7303 * If hkmap set, reset Farsi keymapping.
7304 */
7305 if (p_hkmap && p_altkeymap)
7306 {
7307 p_altkeymap = 0;
7308 p_fkmap = 0;
7309# ifdef FEAT_ARABIC
7310 curwin->w_p_arab = FALSE;
7311# endif
7312 (void)init_chartab();
7313 }
7314
7315 /*
7316 * If fkmap set, reset Hebrew keymapping.
7317 */
7318 if (p_fkmap && !p_altkeymap)
7319 {
7320 p_altkeymap = 1;
7321 p_hkmap = 0;
7322# ifdef FEAT_ARABIC
7323 curwin->w_p_arab = FALSE;
7324# endif
7325 (void)init_chartab();
7326 }
7327#endif
7328
7329#ifdef FEAT_ARABIC
7330 if ((int *)varp == &curwin->w_p_arab)
7331 {
7332 if (curwin->w_p_arab)
7333 {
7334 /*
7335 * 'arabic' is set, handle various sub-settings.
7336 */
7337 if (!p_tbidi)
7338 {
7339 /* set rightleft mode */
7340 if (!curwin->w_p_rl)
7341 {
7342 curwin->w_p_rl = TRUE;
7343 changed_window_setting();
7344 }
7345
7346 /* Enable Arabic shaping (major part of what Arabic requires) */
7347 if (!p_arshape)
7348 {
7349 p_arshape = TRUE;
7350 redraw_later_clear();
7351 }
7352 }
7353
7354 /* Arabic requires a utf-8 encoding, inform the user if its not
7355 * set. */
7356 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007357 {
7358 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7360 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007361 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007362
7363# ifdef FEAT_MBYTE
7364 /* set 'delcombine' */
7365 p_deco = TRUE;
7366# endif
7367
7368# ifdef FEAT_KEYMAP
7369 /* Force-set the necessary keymap for arabic */
7370 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7371 OPT_LOCAL);
7372# endif
7373# ifdef FEAT_FKMAP
7374 p_altkeymap = 0;
7375 p_hkmap = 0;
7376 p_fkmap = 0;
7377 (void)init_chartab();
7378# endif
7379 }
7380 else
7381 {
7382 /*
7383 * 'arabic' is reset, handle various sub-settings.
7384 */
7385 if (!p_tbidi)
7386 {
7387 /* reset rightleft mode */
7388 if (curwin->w_p_rl)
7389 {
7390 curwin->w_p_rl = FALSE;
7391 changed_window_setting();
7392 }
7393
7394 /* 'arabicshape' isn't reset, it is a global option and
7395 * another window may still need it "on". */
7396 }
7397
7398 /* 'delcombine' isn't reset, it is a global option and another
7399 * window may still want it "on". */
7400
7401# ifdef FEAT_KEYMAP
7402 /* Revert to the default keymap */
7403 curbuf->b_p_iminsert = B_IMODE_NONE;
7404 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7405# endif
7406 }
7407 }
7408#endif
7409
7410 /*
7411 * End of handling side effects for bool options.
7412 */
7413
7414 options[opt_idx].flags |= P_WAS_SET;
7415
7416 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7417 if (curwin->w_curswant != MAXCOL)
7418 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7419 check_redraw(options[opt_idx].flags);
7420
7421 return NULL;
7422}
7423
7424/*
7425 * Set the value of a number option, and take care of side effects.
7426 * Returns NULL for success, or an error message for an error.
7427 */
7428 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007429set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430 int opt_idx; /* index in options[] table */
7431 char_u *varp; /* pointer to the option variable */
7432 long value; /* new value */
7433 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007434 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7436 OPT_MODELINE */
7437{
7438 char_u *errmsg = NULL;
7439 long old_value = *(long *)varp;
7440 long old_Rows = Rows; /* remember old Rows */
7441 long old_Columns = Columns; /* remember old Columns */
7442 long *pp = (long *)varp;
7443
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007444 /* Disallow changing some options from secure mode. */
7445 if ((secure
7446#ifdef HAVE_SANDBOX
7447 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007449 ) && (options[opt_idx].flags & P_SECURE))
7450 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451
7452 *pp = value;
7453#ifdef FEAT_EVAL
7454 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007455 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007457#ifdef FEAT_GUI
7458 need_mouse_correct = TRUE;
7459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460
7461 if (curbuf->b_p_sw <= 0)
7462 {
7463 errmsg = e_positive;
7464 curbuf->b_p_sw = curbuf->b_p_ts;
7465 }
7466
7467 /*
7468 * Number options that need some action when changed
7469 */
7470#ifdef FEAT_WINDOWS
7471 if (pp == &p_wh || pp == &p_hh)
7472 {
7473 if (p_wh < 1)
7474 {
7475 errmsg = e_positive;
7476 p_wh = 1;
7477 }
7478 if (p_wmh > p_wh)
7479 {
7480 errmsg = e_winheight;
7481 p_wh = p_wmh;
7482 }
7483 if (p_hh < 0)
7484 {
7485 errmsg = e_positive;
7486 p_hh = 0;
7487 }
7488
7489 /* Change window height NOW */
7490 if (lastwin != firstwin)
7491 {
7492 if (pp == &p_wh && curwin->w_height < p_wh)
7493 win_setheight((int)p_wh);
7494 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7495 win_setheight((int)p_hh);
7496 }
7497 }
7498
7499 /* 'winminheight' */
7500 else if (pp == &p_wmh)
7501 {
7502 if (p_wmh < 0)
7503 {
7504 errmsg = e_positive;
7505 p_wmh = 0;
7506 }
7507 if (p_wmh > p_wh)
7508 {
7509 errmsg = e_winheight;
7510 p_wmh = p_wh;
7511 }
7512 win_setminheight();
7513 }
7514
7515# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007516 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517 {
7518 if (p_wiw < 1)
7519 {
7520 errmsg = e_positive;
7521 p_wiw = 1;
7522 }
7523 if (p_wmw > p_wiw)
7524 {
7525 errmsg = e_winwidth;
7526 p_wiw = p_wmw;
7527 }
7528
7529 /* Change window width NOW */
7530 if (lastwin != firstwin && curwin->w_width < p_wiw)
7531 win_setwidth((int)p_wiw);
7532 }
7533
7534 /* 'winminwidth' */
7535 else if (pp == &p_wmw)
7536 {
7537 if (p_wmw < 0)
7538 {
7539 errmsg = e_positive;
7540 p_wmw = 0;
7541 }
7542 if (p_wmw > p_wiw)
7543 {
7544 errmsg = e_winwidth;
7545 p_wmw = p_wiw;
7546 }
7547 win_setminheight();
7548 }
7549# endif
7550
7551#endif
7552
7553#ifdef FEAT_WINDOWS
7554 /* (re)set last window status line */
7555 else if (pp == &p_ls)
7556 {
7557 last_status(FALSE);
7558 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007559
7560 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007561 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007562 {
7563 shell_new_rows(); /* recompute window positions and heights */
7564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565#endif
7566
7567#ifdef FEAT_GUI
7568 else if (pp == &p_linespace)
7569 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007570 /* Recompute gui.char_height and resize the Vim window to keep the
7571 * same number of lines. */
7572 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 gui_set_shellsize(FALSE, FALSE);
7574 }
7575#endif
7576
7577#ifdef FEAT_FOLDING
7578 /* 'foldlevel' */
7579 else if (pp == &curwin->w_p_fdl)
7580 {
7581 if (curwin->w_p_fdl < 0)
7582 curwin->w_p_fdl = 0;
7583 newFoldLevel();
7584 }
7585
7586 /* 'foldminlevel' */
7587 else if (pp == &curwin->w_p_fml)
7588 {
7589 foldUpdateAll(curwin);
7590 }
7591
7592 /* 'foldnestmax' */
7593 else if (pp == &curwin->w_p_fdn)
7594 {
7595 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7596 foldUpdateAll(curwin);
7597 }
7598
7599 /* 'foldcolumn' */
7600 else if (pp == &curwin->w_p_fdc)
7601 {
7602 if (curwin->w_p_fdc < 0)
7603 {
7604 errmsg = e_positive;
7605 curwin->w_p_fdc = 0;
7606 }
7607 else if (curwin->w_p_fdc > 12)
7608 {
7609 errmsg = e_invarg;
7610 curwin->w_p_fdc = 12;
7611 }
7612 }
7613
7614 /* 'shiftwidth' or 'tabstop' */
7615 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7616 {
7617 if (foldmethodIsIndent(curwin))
7618 foldUpdateAll(curwin);
7619 }
7620#endif /* FEAT_FOLDING */
7621
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007622#ifdef FEAT_MBYTE
7623 /* 'maxcombine' */
7624 else if (pp == &p_mco)
7625 {
7626 if (p_mco > MAX_MCO)
7627 p_mco = MAX_MCO;
7628 else if (p_mco < 0)
7629 p_mco = 0;
7630 screenclear(); /* will re-allocate the screen */
7631 }
7632#endif
7633
Bram Moolenaar071d4272004-06-13 20:20:40 +00007634 else if (pp == &curbuf->b_p_iminsert)
7635 {
7636 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7637 {
7638 errmsg = e_invarg;
7639 curbuf->b_p_iminsert = B_IMODE_NONE;
7640 }
7641 p_iminsert = curbuf->b_p_iminsert;
7642 if (termcap_active) /* don't do this in the alternate screen */
7643 showmode();
7644#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7645 /* Show/unshow value of 'keymap' in status lines. */
7646 status_redraw_curbuf();
7647#endif
7648 }
7649
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007650 else if (pp == &p_window)
7651 {
7652 if (p_window < 1)
7653 p_window = 1;
7654 else if (p_window >= Rows)
7655 p_window = Rows - 1;
7656 }
7657
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658 else if (pp == &curbuf->b_p_imsearch)
7659 {
7660 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7661 {
7662 errmsg = e_invarg;
7663 curbuf->b_p_imsearch = B_IMODE_NONE;
7664 }
7665 p_imsearch = curbuf->b_p_imsearch;
7666 }
7667
7668#ifdef FEAT_TITLE
7669 /* if 'titlelen' has changed, redraw the title */
7670 else if (pp == &p_titlelen)
7671 {
7672 if (p_titlelen < 0)
7673 {
7674 errmsg = e_positive;
7675 p_titlelen = 85;
7676 }
7677 if (starting != NO_SCREEN && old_value != p_titlelen)
7678 need_maketitle = TRUE;
7679 }
7680#endif
7681
7682 /* if p_ch changed value, change the command line height */
7683 else if (pp == &p_ch)
7684 {
7685 if (p_ch < 1)
7686 {
7687 errmsg = e_positive;
7688 p_ch = 1;
7689 }
7690
7691 /* Only compute the new window layout when startup has been
7692 * completed. Otherwise the frame sizes may be wrong. */
7693 if (p_ch != old_value && full_screen
7694#ifdef FEAT_GUI
7695 && !gui.starting
7696#endif
7697 )
7698 command_height(old_value);
7699 }
7700
7701 /* when 'updatecount' changes from zero to non-zero, open swap files */
7702 else if (pp == &p_uc)
7703 {
7704 if (p_uc < 0)
7705 {
7706 errmsg = e_positive;
7707 p_uc = 100;
7708 }
7709 if (p_uc && !old_value)
7710 ml_open_files();
7711 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007712#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007713 else if (pp == &p_mzq)
7714 mzvim_reset_timer();
7715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716
7717 /* sync undo before 'undolevels' changes */
7718 else if (pp == &p_ul)
7719 {
7720 /* use the old value, otherwise u_sync() may not work properly */
7721 p_ul = old_value;
7722 u_sync();
7723 p_ul = value;
7724 }
7725
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007726#ifdef FEAT_LINEBREAK
7727 /* 'numberwidth' must be positive */
7728 else if (pp == &curwin->w_p_nuw)
7729 {
7730 if (curwin->w_p_nuw < 1)
7731 {
7732 errmsg = e_positive;
7733 curwin->w_p_nuw = 1;
7734 }
7735 if (curwin->w_p_nuw > 10)
7736 {
7737 errmsg = e_invarg;
7738 curwin->w_p_nuw = 10;
7739 }
7740 curwin->w_nrwidth_line_count = 0;
7741 }
7742#endif
7743
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 /*
7745 * Check the bounds for numeric options here
7746 */
7747 if (Rows < min_rows() && full_screen)
7748 {
7749 if (errbuf != NULL)
7750 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007751 vim_snprintf((char *)errbuf, errbuflen,
7752 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753 errmsg = errbuf;
7754 }
7755 Rows = min_rows();
7756 }
7757 if (Columns < MIN_COLUMNS && full_screen)
7758 {
7759 if (errbuf != NULL)
7760 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007761 vim_snprintf((char *)errbuf, errbuflen,
7762 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 errmsg = errbuf;
7764 }
7765 Columns = MIN_COLUMNS;
7766 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007767 /* Limit the values to avoid an overflow in Rows * Columns. */
7768 if (Columns > 10000)
7769 Columns = 10000;
7770 if (Rows > 1000)
7771 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772
7773#ifdef DJGPP
7774 /* avoid a crash by checking for a too large value of 'columns' */
7775 if (old_Columns != Columns && full_screen && term_console)
7776 mch_check_columns();
7777#endif
7778
7779 /*
7780 * If the screen (shell) height has been changed, assume it is the
7781 * physical screenheight.
7782 */
7783 if (old_Rows != Rows || old_Columns != Columns)
7784 {
7785 /* Changing the screen size is not allowed while updating the screen. */
7786 if (updating_screen)
7787 *pp = old_value;
7788 else if (full_screen
7789#ifdef FEAT_GUI
7790 && !gui.starting
7791#endif
7792 )
7793 set_shellsize((int)Columns, (int)Rows, TRUE);
7794 else
7795 {
7796 /* Postpone the resizing; check the size and cmdline position for
7797 * messages. */
7798 check_shellsize();
7799 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7800 cmdline_row = Rows - p_ch;
7801 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007802 if (p_window >= Rows)
7803 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804 }
7805
7806 if (curbuf->b_p_sts < 0)
7807 {
7808 errmsg = e_positive;
7809 curbuf->b_p_sts = 0;
7810 }
7811 if (curbuf->b_p_ts <= 0)
7812 {
7813 errmsg = e_positive;
7814 curbuf->b_p_ts = 8;
7815 }
7816 if (curbuf->b_p_tw < 0)
7817 {
7818 errmsg = e_positive;
7819 curbuf->b_p_tw = 0;
7820 }
7821 if (p_tm < 0)
7822 {
7823 errmsg = e_positive;
7824 p_tm = 0;
7825 }
7826 if ((curwin->w_p_scr <= 0
7827 || (curwin->w_p_scr > curwin->w_height
7828 && curwin->w_height > 0))
7829 && full_screen)
7830 {
7831 if (pp == &(curwin->w_p_scr))
7832 {
7833 if (curwin->w_p_scr != 0)
7834 errmsg = e_scroll;
7835 win_comp_scroll(curwin);
7836 }
7837 /* If 'scroll' became invalid because of a side effect silently adjust
7838 * it. */
7839 else if (curwin->w_p_scr <= 0)
7840 curwin->w_p_scr = 1;
7841 else /* curwin->w_p_scr > curwin->w_height */
7842 curwin->w_p_scr = curwin->w_height;
7843 }
7844 if (p_report < 0)
7845 {
7846 errmsg = e_positive;
7847 p_report = 1;
7848 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007849 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 {
7851 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7852 p_sj = Rows / 2;
7853 else
7854 {
7855 errmsg = e_scroll;
7856 p_sj = 1;
7857 }
7858 }
7859 if (p_so < 0 && full_screen)
7860 {
7861 errmsg = e_scroll;
7862 p_so = 0;
7863 }
7864 if (p_siso < 0 && full_screen)
7865 {
7866 errmsg = e_positive;
7867 p_siso = 0;
7868 }
7869#ifdef FEAT_CMDWIN
7870 if (p_cwh < 1)
7871 {
7872 errmsg = e_positive;
7873 p_cwh = 1;
7874 }
7875#endif
7876 if (p_ut < 0)
7877 {
7878 errmsg = e_positive;
7879 p_ut = 2000;
7880 }
7881 if (p_ss < 0)
7882 {
7883 errmsg = e_positive;
7884 p_ss = 0;
7885 }
7886
7887 /* May set global value for local option. */
7888 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7889 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7890
7891 options[opt_idx].flags |= P_WAS_SET;
7892
7893 comp_col(); /* in case 'columns' or 'ls' changed */
7894 if (curwin->w_curswant != MAXCOL)
7895 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7896 check_redraw(options[opt_idx].flags);
7897
7898 return errmsg;
7899}
7900
7901/*
7902 * Called after an option changed: check if something needs to be redrawn.
7903 */
7904 static void
7905check_redraw(flags)
7906 long_u flags;
7907{
7908 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7909 int clear = (flags & P_RCLR) == P_RCLR;
7910 int all = ((flags & P_RALL) == P_RALL || clear);
7911
7912#ifdef FEAT_WINDOWS
7913 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7914 status_redraw_all();
7915#endif
7916
7917 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7918 changed_window_setting();
7919 if (flags & P_RBUF)
7920 redraw_curbuf_later(NOT_VALID);
7921 if (clear)
7922 redraw_all_later(CLEAR);
7923 else if (all)
7924 redraw_all_later(NOT_VALID);
7925}
7926
7927/*
7928 * Find index for option 'arg'.
7929 * Return -1 if not found.
7930 */
7931 static int
7932findoption(arg)
7933 char_u *arg;
7934{
7935 int opt_idx;
7936 char *s, *p;
7937 static short quick_tab[27] = {0, 0}; /* quick access table */
7938 int is_term_opt;
7939
7940 /*
7941 * For first call: Initialize the quick-access table.
7942 * It contains the index for the first option that starts with a certain
7943 * letter. There are 26 letters, plus the first "t_" option.
7944 */
7945 if (quick_tab[1] == 0)
7946 {
7947 p = options[0].fullname;
7948 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7949 {
7950 if (s[0] != p[0])
7951 {
7952 if (s[0] == 't' && s[1] == '_')
7953 quick_tab[26] = opt_idx;
7954 else
7955 quick_tab[CharOrdLow(s[0])] = opt_idx;
7956 }
7957 p = s;
7958 }
7959 }
7960
7961 /*
7962 * Check for name starting with an illegal character.
7963 */
7964#ifdef EBCDIC
7965 if (!islower(arg[0]))
7966#else
7967 if (arg[0] < 'a' || arg[0] > 'z')
7968#endif
7969 return -1;
7970
7971 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7972 if (is_term_opt)
7973 opt_idx = quick_tab[26];
7974 else
7975 opt_idx = quick_tab[CharOrdLow(arg[0])];
7976 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7977 {
7978 if (STRCMP(arg, s) == 0) /* match full name */
7979 break;
7980 }
7981 if (s == NULL && !is_term_opt)
7982 {
7983 opt_idx = quick_tab[CharOrdLow(arg[0])];
7984 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7985 {
7986 s = options[opt_idx].shortname;
7987 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7988 break;
7989 s = NULL;
7990 }
7991 }
7992 if (s == NULL)
7993 opt_idx = -1;
7994 return opt_idx;
7995}
7996
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007997#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998/*
7999 * Get the value for an option.
8000 *
8001 * Returns:
8002 * Number or Toggle option: 1, *numval gets value.
8003 * String option: 0, *stringval gets allocated string.
8004 * Hidden Number or Toggle option: -1.
8005 * hidden String option: -2.
8006 * unknown option: -3.
8007 */
8008 int
8009get_option_value(name, numval, stringval, opt_flags)
8010 char_u *name;
8011 long *numval;
8012 char_u **stringval; /* NULL when only checking existance */
8013 int opt_flags;
8014{
8015 int opt_idx;
8016 char_u *varp;
8017
8018 opt_idx = findoption(name);
8019 if (opt_idx < 0) /* unknown option */
8020 return -3;
8021
8022 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8023
8024 if (options[opt_idx].flags & P_STRING)
8025 {
8026 if (varp == NULL) /* hidden option */
8027 return -2;
8028 if (stringval != NULL)
8029 {
8030#ifdef FEAT_CRYPT
8031 /* never return the value of the crypt key */
8032 if ((char_u **)varp == &curbuf->b_p_key)
8033 *stringval = vim_strsave((char_u *)"*****");
8034 else
8035#endif
8036 *stringval = vim_strsave(*(char_u **)(varp));
8037 }
8038 return 0;
8039 }
8040
8041 if (varp == NULL) /* hidden option */
8042 return -1;
8043 if (options[opt_idx].flags & P_NUM)
8044 *numval = *(long *)varp;
8045 else
8046 {
8047 /* Special case: 'modified' is b_changed, but we also want to consider
8048 * it set when 'ff' or 'fenc' changed. */
8049 if ((int *)varp == &curbuf->b_changed)
8050 *numval = curbufIsChanged();
8051 else
8052 *numval = *(int *)varp;
8053 }
8054 return 1;
8055}
8056#endif
8057
8058/*
8059 * Set the value of option "name".
8060 * Use "string" for string options, use "number" for other options.
8061 */
8062 void
8063set_option_value(name, number, string, opt_flags)
8064 char_u *name;
8065 long number;
8066 char_u *string;
8067 int opt_flags; /* OPT_LOCAL or 0 (both) */
8068{
8069 int opt_idx;
8070 char_u *varp;
8071 int flags;
8072
8073 opt_idx = findoption(name);
8074 if (opt_idx == -1)
8075 EMSG2(_("E355: Unknown option: %s"), name);
8076 else
8077 {
8078 flags = options[opt_idx].flags;
8079#ifdef HAVE_SANDBOX
8080 /* Disallow changing some options in the sandbox */
8081 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008082 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008084 return;
8085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008087 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 set_string_option(opt_idx, string, opt_flags);
8089 else
8090 {
8091 varp = get_varp(&options[opt_idx]);
8092 if (varp != NULL) /* hidden option is not changed */
8093 {
8094 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008095 (void)set_num_option(opt_idx, varp, number,
8096 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008098 (void)set_bool_option(opt_idx, varp, (int)number,
8099 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100 }
8101 }
8102 }
8103}
8104
8105/*
8106 * Get the terminal code for a terminal option.
8107 * Returns NULL when not found.
8108 */
8109 char_u *
8110get_term_code(tname)
8111 char_u *tname;
8112{
8113 int opt_idx;
8114 char_u *varp;
8115
8116 if (tname[0] != 't' || tname[1] != '_' ||
8117 tname[2] == NUL || tname[3] == NUL)
8118 return NULL;
8119 if ((opt_idx = findoption(tname)) >= 0)
8120 {
8121 varp = get_varp(&(options[opt_idx]));
8122 if (varp != NULL)
8123 varp = *(char_u **)(varp);
8124 return varp;
8125 }
8126 return find_termcode(tname + 2);
8127}
8128
8129 char_u *
8130get_highlight_default()
8131{
8132 int i;
8133
8134 i = findoption((char_u *)"hl");
8135 if (i >= 0)
8136 return options[i].def_val[VI_DEFAULT];
8137 return (char_u *)NULL;
8138}
8139
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008140#if defined(FEAT_MBYTE) || defined(PROTO)
8141 char_u *
8142get_encoding_default()
8143{
8144 int i;
8145
8146 i = findoption((char_u *)"enc");
8147 if (i >= 0)
8148 return options[i].def_val[VI_DEFAULT];
8149 return (char_u *)NULL;
8150}
8151#endif
8152
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153/*
8154 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8155 */
8156 static int
8157find_key_option(arg)
8158 char_u *arg;
8159{
8160 int key;
8161 int modifiers;
8162
8163 /*
8164 * Don't use get_special_key_code() for t_xx, we don't want it to call
8165 * add_termcap_entry().
8166 */
8167 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8168 key = TERMCAP2KEY(arg[2], arg[3]);
8169 else
8170 {
8171 --arg; /* put arg at the '<' */
8172 modifiers = 0;
8173 key = find_special_key(&arg, &modifiers, TRUE);
8174 if (modifiers) /* can't handle modifiers here */
8175 key = 0;
8176 }
8177 return key;
8178}
8179
8180/*
8181 * if 'all' == 0: show changed options
8182 * if 'all' == 1: show all normal options
8183 * if 'all' == 2: show all terminal options
8184 */
8185 static void
8186showoptions(all, opt_flags)
8187 int all;
8188 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8189{
8190 struct vimoption *p;
8191 int col;
8192 int isterm;
8193 char_u *varp;
8194 struct vimoption **items;
8195 int item_count;
8196 int run;
8197 int row, rows;
8198 int cols;
8199 int i;
8200 int len;
8201
8202#define INC 20
8203#define GAP 3
8204
8205 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8206 PARAM_COUNT));
8207 if (items == NULL)
8208 return;
8209
8210 /* Highlight title */
8211 if (all == 2)
8212 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8213 else if (opt_flags & OPT_GLOBAL)
8214 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8215 else if (opt_flags & OPT_LOCAL)
8216 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8217 else
8218 MSG_PUTS_TITLE(_("\n--- Options ---"));
8219
8220 /*
8221 * do the loop two times:
8222 * 1. display the short items
8223 * 2. display the long items (only strings and numbers)
8224 */
8225 for (run = 1; run <= 2 && !got_int; ++run)
8226 {
8227 /*
8228 * collect the items in items[]
8229 */
8230 item_count = 0;
8231 for (p = &options[0]; p->fullname != NULL; p++)
8232 {
8233 varp = NULL;
8234 isterm = istermoption(p);
8235 if (opt_flags != 0)
8236 {
8237 if (p->indir != PV_NONE && !isterm)
8238 varp = get_varp_scope(p, opt_flags);
8239 }
8240 else
8241 varp = get_varp(p);
8242 if (varp != NULL
8243 && ((all == 2 && isterm)
8244 || (all == 1 && !isterm)
8245 || (all == 0 && !optval_default(p, varp))))
8246 {
8247 if (p->flags & P_BOOL)
8248 len = 1; /* a toggle option fits always */
8249 else
8250 {
8251 option_value2string(p, opt_flags);
8252 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8253 }
8254 if ((len <= INC - GAP && run == 1) ||
8255 (len > INC - GAP && run == 2))
8256 items[item_count++] = p;
8257 }
8258 }
8259
8260 /*
8261 * display the items
8262 */
8263 if (run == 1)
8264 {
8265 cols = (Columns + GAP - 3) / INC;
8266 if (cols == 0)
8267 cols = 1;
8268 rows = (item_count + cols - 1) / cols;
8269 }
8270 else /* run == 2 */
8271 rows = item_count;
8272 for (row = 0; row < rows && !got_int; ++row)
8273 {
8274 msg_putchar('\n'); /* go to next line */
8275 if (got_int) /* 'q' typed in more */
8276 break;
8277 col = 0;
8278 for (i = row; i < item_count; i += rows)
8279 {
8280 msg_col = col; /* make columns */
8281 showoneopt(items[i], opt_flags);
8282 col += INC;
8283 }
8284 out_flush();
8285 ui_breakcheck();
8286 }
8287 }
8288 vim_free(items);
8289}
8290
8291/*
8292 * Return TRUE if option "p" has its default value.
8293 */
8294 static int
8295optval_default(p, varp)
8296 struct vimoption *p;
8297 char_u *varp;
8298{
8299 int dvi;
8300
8301 if (varp == NULL)
8302 return TRUE; /* hidden option is always at default */
8303 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8304 if (p->flags & P_NUM)
8305 return (*(long *)varp == (long)p->def_val[dvi]);
8306 if (p->flags & P_BOOL)
8307 /* the cast to long is required for Manx C */
8308 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8309 /* P_STRING */
8310 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8311}
8312
8313/*
8314 * showoneopt: show the value of one option
8315 * must not be called with a hidden option!
8316 */
8317 static void
8318showoneopt(p, opt_flags)
8319 struct vimoption *p;
8320 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8321{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008322 char_u *varp;
8323 int save_silent = silent_mode;
8324
8325 silent_mode = FALSE;
8326 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327
8328 varp = get_varp_scope(p, opt_flags);
8329
8330 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8331 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8332 ? !curbufIsChanged() : !*(int *)varp))
8333 MSG_PUTS("no");
8334 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8335 MSG_PUTS("--");
8336 else
8337 MSG_PUTS(" ");
8338 MSG_PUTS(p->fullname);
8339 if (!(p->flags & P_BOOL))
8340 {
8341 msg_putchar('=');
8342 /* put value string in NameBuff */
8343 option_value2string(p, opt_flags);
8344 msg_outtrans(NameBuff);
8345 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008346
8347 silent_mode = save_silent;
8348 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008349}
8350
8351/*
8352 * Write modified options as ":set" commands to a file.
8353 *
8354 * There are three values for "opt_flags":
8355 * OPT_GLOBAL: Write global option values and fresh values of
8356 * buffer-local options (used for start of a session
8357 * file).
8358 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8359 * curwin (used for a vimrc file).
8360 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8361 * and local values for window-local options of
8362 * curwin. Local values are also written when at the
8363 * default value, because a modeline or autocommand
8364 * may have set them when doing ":edit file" and the
8365 * user has set them back at the default or fresh
8366 * value.
8367 * When "local_only" is TRUE, don't write fresh
8368 * values, only local values (for ":mkview").
8369 * (fresh value = value used for a new buffer or window for a local option).
8370 *
8371 * Return FAIL on error, OK otherwise.
8372 */
8373 int
8374makeset(fd, opt_flags, local_only)
8375 FILE *fd;
8376 int opt_flags;
8377 int local_only;
8378{
8379 struct vimoption *p;
8380 char_u *varp; /* currently used value */
8381 char_u *varp_fresh; /* local value */
8382 char_u *varp_local = NULL; /* fresh value */
8383 char *cmd;
8384 int round;
8385
8386 /*
8387 * The options that don't have a default (terminal name, columns, lines)
8388 * are never written. Terminal options are also not written.
8389 */
8390 for (p = &options[0]; !istermoption(p); p++)
8391 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8392 {
8393 /* skip global option when only doing locals */
8394 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8395 continue;
8396
8397 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8398 * file, they are always buffer-specific. */
8399 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8400 continue;
8401
8402 /* Global values are only written when not at the default value. */
8403 varp = get_varp_scope(p, opt_flags);
8404 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8405 continue;
8406
8407 round = 2;
8408 if (p->indir != PV_NONE)
8409 {
8410 if (p->var == VAR_WIN)
8411 {
8412 /* skip window-local option when only doing globals */
8413 if (!(opt_flags & OPT_LOCAL))
8414 continue;
8415 /* When fresh value of window-local option is not at the
8416 * default, need to write it too. */
8417 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8418 {
8419 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8420 if (!optval_default(p, varp_fresh))
8421 {
8422 round = 1;
8423 varp_local = varp;
8424 varp = varp_fresh;
8425 }
8426 }
8427 }
8428 }
8429
8430 /* Round 1: fresh value for window-local options.
8431 * Round 2: other values */
8432 for ( ; round <= 2; varp = varp_local, ++round)
8433 {
8434 if (round == 1 || (opt_flags & OPT_GLOBAL))
8435 cmd = "set";
8436 else
8437 cmd = "setlocal";
8438
8439 if (p->flags & P_BOOL)
8440 {
8441 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8442 return FAIL;
8443 }
8444 else if (p->flags & P_NUM)
8445 {
8446 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8447 return FAIL;
8448 }
8449 else /* P_STRING */
8450 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008451#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8452 int do_endif = FALSE;
8453
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454 /* Don't set 'syntax' and 'filetype' again if the value is
8455 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008456 if (
8457# if defined(FEAT_SYN_HL)
8458 p->indir == PV_SYN
8459# if defined(FEAT_AUTOCMD)
8460 ||
8461# endif
8462# endif
8463# if defined(FEAT_AUTOCMD)
8464 p->indir == PV_FT)
8465# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 {
8467 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8468 *(char_u **)(varp)) < 0
8469 || put_eol(fd) < 0)
8470 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008471 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008473#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8475 (p->flags & P_EXPAND) != 0) == FAIL)
8476 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008477#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8478 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479 {
8480 if (put_line(fd, "endif") == FAIL)
8481 return FAIL;
8482 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484 }
8485 }
8486 }
8487 return OK;
8488}
8489
8490#if defined(FEAT_FOLDING) || defined(PROTO)
8491/*
8492 * Generate set commands for the local fold options only. Used when
8493 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8494 */
8495 int
8496makefoldset(fd)
8497 FILE *fd;
8498{
8499 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8500# ifdef FEAT_EVAL
8501 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8502 == FAIL
8503# endif
8504 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8505 == FAIL
8506 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8507 == FAIL
8508 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8509 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8510 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8511 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8512 )
8513 return FAIL;
8514
8515 return OK;
8516}
8517#endif
8518
8519 static int
8520put_setstring(fd, cmd, name, valuep, expand)
8521 FILE *fd;
8522 char *cmd;
8523 char *name;
8524 char_u **valuep;
8525 int expand;
8526{
8527 char_u *s;
8528 char_u buf[MAXPATHL];
8529
8530 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8531 return FAIL;
8532 if (*valuep != NULL)
8533 {
8534 /* Output 'pastetoggle' as key names. For other
8535 * options some characters have to be escaped with
8536 * CTRL-V or backslash */
8537 if (valuep == &p_pt)
8538 {
8539 s = *valuep;
8540 while (*s != NUL)
8541 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8542 return FAIL;
8543 }
8544 else if (expand)
8545 {
8546 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8547 if (put_escstr(fd, buf, 2) == FAIL)
8548 return FAIL;
8549 }
8550 else if (put_escstr(fd, *valuep, 2) == FAIL)
8551 return FAIL;
8552 }
8553 if (put_eol(fd) < 0)
8554 return FAIL;
8555 return OK;
8556}
8557
8558 static int
8559put_setnum(fd, cmd, name, valuep)
8560 FILE *fd;
8561 char *cmd;
8562 char *name;
8563 long *valuep;
8564{
8565 long wc;
8566
8567 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8568 return FAIL;
8569 if (wc_use_keyname((char_u *)valuep, &wc))
8570 {
8571 /* print 'wildchar' and 'wildcharm' as a key name */
8572 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8573 return FAIL;
8574 }
8575 else if (fprintf(fd, "%ld", *valuep) < 0)
8576 return FAIL;
8577 if (put_eol(fd) < 0)
8578 return FAIL;
8579 return OK;
8580}
8581
8582 static int
8583put_setbool(fd, cmd, name, value)
8584 FILE *fd;
8585 char *cmd;
8586 char *name;
8587 int value;
8588{
8589 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8590 || put_eol(fd) < 0)
8591 return FAIL;
8592 return OK;
8593}
8594
8595/*
8596 * Clear all the terminal options.
8597 * If the option has been allocated, free the memory.
8598 * Terminal options are never hidden or indirect.
8599 */
8600 void
8601clear_termoptions()
8602{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603 /*
8604 * Reset a few things before clearing the old options. This may cause
8605 * outputting a few things that the terminal doesn't understand, but the
8606 * screen will be cleared later, so this is OK.
8607 */
8608#ifdef FEAT_MOUSE_TTY
8609 mch_setmouse(FALSE); /* switch mouse off */
8610#endif
8611#ifdef FEAT_TITLE
8612 mch_restore_title(3); /* restore window titles */
8613#endif
8614#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8615 /* When starting the GUI close the display opened for the clipboard.
8616 * After restoring the title, because that will need the display. */
8617 if (gui.starting)
8618 clear_xterm_clip();
8619#endif
8620#ifdef WIN3264
8621 /*
8622 * Check if this is allowed now.
8623 */
8624 if (can_end_termcap_mode(FALSE) == TRUE)
8625#endif
8626 stoptermcap(); /* stop termcap mode */
8627
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008628 free_termoptions();
8629}
8630
8631 void
8632free_termoptions()
8633{
8634 struct vimoption *p;
8635
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636 for (p = &options[0]; p->fullname != NULL; p++)
8637 if (istermoption(p))
8638 {
8639 if (p->flags & P_ALLOCED)
8640 free_string_option(*(char_u **)(p->var));
8641 if (p->flags & P_DEF_ALLOCED)
8642 free_string_option(p->def_val[VI_DEFAULT]);
8643 *(char_u **)(p->var) = empty_option;
8644 p->def_val[VI_DEFAULT] = empty_option;
8645 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8646 }
8647 clear_termcodes();
8648}
8649
8650/*
8651 * Set the terminal option defaults to the current value.
8652 * Used after setting the terminal name.
8653 */
8654 void
8655set_term_defaults()
8656{
8657 struct vimoption *p;
8658
8659 for (p = &options[0]; p->fullname != NULL; p++)
8660 {
8661 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8662 {
8663 if (p->flags & P_DEF_ALLOCED)
8664 {
8665 free_string_option(p->def_val[VI_DEFAULT]);
8666 p->flags &= ~P_DEF_ALLOCED;
8667 }
8668 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8669 if (p->flags & P_ALLOCED)
8670 {
8671 p->flags |= P_DEF_ALLOCED;
8672 p->flags &= ~P_ALLOCED; /* don't free the value now */
8673 }
8674 }
8675 }
8676}
8677
8678/*
8679 * return TRUE if 'p' starts with 't_'
8680 */
8681 static int
8682istermoption(p)
8683 struct vimoption *p;
8684{
8685 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8686}
8687
8688/*
8689 * Compute columns for ruler and shown command. 'sc_col' is also used to
8690 * decide what the maximum length of a message on the status line can be.
8691 * If there is a status line for the last window, 'sc_col' is independent
8692 * of 'ru_col'.
8693 */
8694
8695#define COL_RULER 17 /* columns needed by standard ruler */
8696
8697 void
8698comp_col()
8699{
8700#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8701 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8702
8703 sc_col = 0;
8704 ru_col = 0;
8705 if (p_ru)
8706 {
8707#ifdef FEAT_STL_OPT
8708 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8709#else
8710 ru_col = COL_RULER + 1;
8711#endif
8712 /* no last status line, adjust sc_col */
8713 if (!last_has_status)
8714 sc_col = ru_col;
8715 }
8716 if (p_sc)
8717 {
8718 sc_col += SHOWCMD_COLS;
8719 if (!p_ru || last_has_status) /* no need for separating space */
8720 ++sc_col;
8721 }
8722 sc_col = Columns - sc_col;
8723 ru_col = Columns - ru_col;
8724 if (sc_col <= 0) /* screen too narrow, will become a mess */
8725 sc_col = 1;
8726 if (ru_col <= 0)
8727 ru_col = 1;
8728#else
8729 sc_col = Columns;
8730 ru_col = Columns;
8731#endif
8732}
8733
8734/*
8735 * Get pointer to option variable, depending on local or global scope.
8736 */
8737 static char_u *
8738get_varp_scope(p, opt_flags)
8739 struct vimoption *p;
8740 int opt_flags;
8741{
8742 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8743 {
8744 if (p->var == VAR_WIN)
8745 return (char_u *)GLOBAL_WO(get_varp(p));
8746 return p->var;
8747 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008748 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749 {
8750 switch ((int)p->indir)
8751 {
8752#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008753 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
8754 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
8755 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008757 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
8758 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
8759 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008760 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008761 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008763 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
8764 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765#endif
8766#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008767 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
8768 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008770#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008771 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 }
8774 return NULL; /* "cannot happen" */
8775 }
8776 return get_varp(p);
8777}
8778
8779/*
8780 * Get pointer to option variable.
8781 */
8782 static char_u *
8783get_varp(p)
8784 struct vimoption *p;
8785{
8786 /* hidden option, always return NULL */
8787 if (p->var == NULL)
8788 return NULL;
8789
8790 switch ((int)p->indir)
8791 {
8792 case PV_NONE: return p->var;
8793
8794 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008795 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008797 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008799 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008801 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008803 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8805#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008806 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008808 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8810#endif
8811#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008812 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008814 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8816#endif
8817#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008818 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008820 case PV_GP: return *curbuf->b_p_gp != NUL
8821 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8822 case PV_MP: return *curbuf->b_p_mp != NUL
8823 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008825#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008826 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008827 ? (char_u *)&(curwin->w_p_stl) : p->var;
8828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829
8830#ifdef FEAT_ARABIC
8831 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8832#endif
8833 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008834#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00008835 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8836#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008837#ifdef FEAT_SYN_HL
8838 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
8839 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
8840#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008841#ifdef FEAT_DIFF
8842 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8843#endif
8844#ifdef FEAT_FOLDING
8845 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8846 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8847 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8848 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8849 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8850 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8851 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8852# ifdef FEAT_EVAL
8853 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8854 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8855# endif
8856 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8857#endif
8858 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008859#ifdef FEAT_LINEBREAK
8860 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8861#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008862#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00008863 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8864#endif
8865#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8866 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8867#endif
8868#ifdef FEAT_RIGHTLEFT
8869 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8870 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8871#endif
8872 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8873 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8874#ifdef FEAT_LINEBREAK
8875 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8876#endif
8877#ifdef FEAT_SCROLLBIND
8878 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8879#endif
8880
8881 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8882 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8883#ifdef FEAT_MBYTE
8884 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8885#endif
8886#if defined(FEAT_QUICKFIX)
8887 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8888 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8889#endif
8890 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8891 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8892#ifdef FEAT_CINDENT
8893 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8894 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8895 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8896#endif
8897#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8898 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8899#endif
8900#ifdef FEAT_COMMENTS
8901 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8902#endif
8903#ifdef FEAT_FOLDING
8904 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8905#endif
8906#ifdef FEAT_INS_EXPAND
8907 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8908#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008909#ifdef FEAT_COMPL_FUNC
8910 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008911 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8914 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8915#ifdef FEAT_MBYTE
8916 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8917#endif
8918 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8919#ifdef FEAT_AUTOCMD
8920 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8921#endif
8922 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008923 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8925 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8926 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8927 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8928#ifdef FEAT_FIND_ID
8929# ifdef FEAT_EVAL
8930 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8931# endif
8932#endif
8933#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8934 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8935 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8936#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008937#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008938 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940#ifdef FEAT_CRYPT
8941 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8942#endif
8943#ifdef FEAT_LISP
8944 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8945#endif
8946 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8947 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8948 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8949 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8950 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8951#ifdef FEAT_OSFILETYPE
8952 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8953#endif
8954 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008955#ifdef FEAT_TEXTOBJ
8956 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8959#ifdef FEAT_SMARTINDENT
8960 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8961#endif
8962#ifndef SHORT_FNAME
8963 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8964#endif
8965 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8966#ifdef FEAT_SEARCHPATH
8967 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8968#endif
8969 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8970#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008971 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008972 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
8973#endif
8974#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008975 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008976 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008977 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978#endif
8979 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8980 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8981 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8982 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8983 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8984#ifdef FEAT_KEYMAP
8985 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8986#endif
8987 default: EMSG(_("E356: get_varp ERROR"));
8988 }
8989 /* always return a valid pointer to avoid a crash! */
8990 return (char_u *)&(curbuf->b_p_wm);
8991}
8992
8993/*
8994 * Get the value of 'equalprg', either the buffer-local one or the global one.
8995 */
8996 char_u *
8997get_equalprg()
8998{
8999 if (*curbuf->b_p_ep == NUL)
9000 return p_ep;
9001 return curbuf->b_p_ep;
9002}
9003
9004#if defined(FEAT_WINDOWS) || defined(PROTO)
9005/*
9006 * Copy options from one window to another.
9007 * Used when splitting a window.
9008 */
9009 void
9010win_copy_options(wp_from, wp_to)
9011 win_T *wp_from;
9012 win_T *wp_to;
9013{
9014 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9015 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9016# ifdef FEAT_RIGHTLEFT
9017# ifdef FEAT_FKMAP
9018 /* Is this right? */
9019 wp_to->w_farsi = wp_from->w_farsi;
9020# endif
9021# endif
9022}
9023#endif
9024
9025/*
9026 * Copy the options from one winopt_T to another.
9027 * Doesn't free the old option values in "to", use clear_winopt() for that.
9028 * The 'scroll' option is not copied, because it depends on the window height.
9029 * The 'previewwindow' option is reset, there can be only one preview window.
9030 */
9031 void
9032copy_winopt(from, to)
9033 winopt_T *from;
9034 winopt_T *to;
9035{
9036#ifdef FEAT_ARABIC
9037 to->wo_arab = from->wo_arab;
9038#endif
9039 to->wo_list = from->wo_list;
9040 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009041#ifdef FEAT_LINEBREAK
9042 to->wo_nuw = from->wo_nuw;
9043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044#ifdef FEAT_RIGHTLEFT
9045 to->wo_rl = from->wo_rl;
9046 to->wo_rlc = vim_strsave(from->wo_rlc);
9047#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009048#ifdef FEAT_STL_OPT
9049 to->wo_stl = vim_strsave(from->wo_stl);
9050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009051 to->wo_wrap = from->wo_wrap;
9052#ifdef FEAT_LINEBREAK
9053 to->wo_lbr = from->wo_lbr;
9054#endif
9055#ifdef FEAT_SCROLLBIND
9056 to->wo_scb = from->wo_scb;
9057#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009058#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009059 to->wo_spell = from->wo_spell;
9060#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009061#ifdef FEAT_SYN_HL
9062 to->wo_cuc = from->wo_cuc;
9063 to->wo_cul = from->wo_cul;
9064#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065#ifdef FEAT_DIFF
9066 to->wo_diff = from->wo_diff;
9067#endif
9068#ifdef FEAT_FOLDING
9069 to->wo_fdc = from->wo_fdc;
9070 to->wo_fen = from->wo_fen;
9071 to->wo_fdi = vim_strsave(from->wo_fdi);
9072 to->wo_fml = from->wo_fml;
9073 to->wo_fdl = from->wo_fdl;
9074 to->wo_fdm = vim_strsave(from->wo_fdm);
9075 to->wo_fdn = from->wo_fdn;
9076# ifdef FEAT_EVAL
9077 to->wo_fde = vim_strsave(from->wo_fde);
9078 to->wo_fdt = vim_strsave(from->wo_fdt);
9079# endif
9080 to->wo_fmr = vim_strsave(from->wo_fmr);
9081#endif
9082 check_winopt(to); /* don't want NULL pointers */
9083}
9084
9085/*
9086 * Check string options in a window for a NULL value.
9087 */
9088 void
9089check_win_options(win)
9090 win_T *win;
9091{
9092 check_winopt(&win->w_onebuf_opt);
9093 check_winopt(&win->w_allbuf_opt);
9094}
9095
9096/*
9097 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9098 */
9099/*ARGSUSED*/
9100 void
9101check_winopt(wop)
9102 winopt_T *wop;
9103{
9104#ifdef FEAT_FOLDING
9105 check_string_option(&wop->wo_fdi);
9106 check_string_option(&wop->wo_fdm);
9107# ifdef FEAT_EVAL
9108 check_string_option(&wop->wo_fde);
9109 check_string_option(&wop->wo_fdt);
9110# endif
9111 check_string_option(&wop->wo_fmr);
9112#endif
9113#ifdef FEAT_RIGHTLEFT
9114 check_string_option(&wop->wo_rlc);
9115#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009116#ifdef FEAT_STL_OPT
9117 check_string_option(&wop->wo_stl);
9118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009119}
9120
9121/*
9122 * Free the allocated memory inside a winopt_T.
9123 */
9124/*ARGSUSED*/
9125 void
9126clear_winopt(wop)
9127 winopt_T *wop;
9128{
9129#ifdef FEAT_FOLDING
9130 clear_string_option(&wop->wo_fdi);
9131 clear_string_option(&wop->wo_fdm);
9132# ifdef FEAT_EVAL
9133 clear_string_option(&wop->wo_fde);
9134 clear_string_option(&wop->wo_fdt);
9135# endif
9136 clear_string_option(&wop->wo_fmr);
9137#endif
9138#ifdef FEAT_RIGHTLEFT
9139 clear_string_option(&wop->wo_rlc);
9140#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009141#ifdef FEAT_STL_OPT
9142 clear_string_option(&wop->wo_stl);
9143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144}
9145
9146/*
9147 * Copy global option values to local options for one buffer.
9148 * Used when creating a new buffer and sometimes when entering a buffer.
9149 * flags:
9150 * BCO_ENTER We will enter the buf buffer.
9151 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9152 * appropriate.
9153 * BCO_NOHELP Don't copy the values to a help buffer.
9154 */
9155 void
9156buf_copy_options(buf, flags)
9157 buf_T *buf;
9158 int flags;
9159{
9160 int should_copy = TRUE;
9161 char_u *save_p_isk = NULL; /* init for GCC */
9162 int dont_do_help;
9163 int did_isk = FALSE;
9164
9165 /*
9166 * Don't do anything of the buffer is invalid.
9167 */
9168 if (buf == NULL || !buf_valid(buf))
9169 return;
9170
9171 /*
9172 * Skip this when the option defaults have not been set yet. Happens when
9173 * main() allocates the first buffer.
9174 */
9175 if (p_cpo != NULL)
9176 {
9177 /*
9178 * Always copy when entering and 'cpo' contains 'S'.
9179 * Don't copy when already initialized.
9180 * Don't copy when 'cpo' contains 's' and not entering.
9181 * 'S' BCO_ENTER initialized 's' should_copy
9182 * yes yes X X TRUE
9183 * yes no yes X FALSE
9184 * no X yes X FALSE
9185 * X no no yes FALSE
9186 * X no no no TRUE
9187 * no yes no X TRUE
9188 */
9189 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9190 && (buf->b_p_initialized
9191 || (!(flags & BCO_ENTER)
9192 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9193 should_copy = FALSE;
9194
9195 if (should_copy || (flags & BCO_ALWAYS))
9196 {
9197 /* Don't copy the options specific to a help buffer when
9198 * BCO_NOHELP is given or the options were initialized already
9199 * (jumping back to a help file with CTRL-T or CTRL-O) */
9200 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9201 || buf->b_p_initialized;
9202 if (dont_do_help) /* don't free b_p_isk */
9203 {
9204 save_p_isk = buf->b_p_isk;
9205 buf->b_p_isk = NULL;
9206 }
9207 /*
9208 * Always free the allocated strings.
9209 * If not already initialized, set 'readonly' and copy 'fileformat'.
9210 */
9211 if (!buf->b_p_initialized)
9212 {
9213 free_buf_options(buf, TRUE);
9214 buf->b_p_ro = FALSE; /* don't copy readonly */
9215 buf->b_p_tx = p_tx;
9216#ifdef FEAT_MBYTE
9217 buf->b_p_fenc = vim_strsave(p_fenc);
9218#endif
9219 buf->b_p_ff = vim_strsave(p_ff);
9220#if defined(FEAT_QUICKFIX)
9221 buf->b_p_bh = empty_option;
9222 buf->b_p_bt = empty_option;
9223#endif
9224 }
9225 else
9226 free_buf_options(buf, FALSE);
9227
9228 buf->b_p_ai = p_ai;
9229 buf->b_p_ai_nopaste = p_ai_nopaste;
9230 buf->b_p_sw = p_sw;
9231 buf->b_p_tw = p_tw;
9232 buf->b_p_tw_nopaste = p_tw_nopaste;
9233 buf->b_p_tw_nobin = p_tw_nobin;
9234 buf->b_p_wm = p_wm;
9235 buf->b_p_wm_nopaste = p_wm_nopaste;
9236 buf->b_p_wm_nobin = p_wm_nobin;
9237 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009238#ifdef FEAT_MBYTE
9239 buf->b_p_bomb = p_bomb;
9240#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009241 buf->b_p_et = p_et;
9242 buf->b_p_et_nobin = p_et_nobin;
9243 buf->b_p_ml = p_ml;
9244 buf->b_p_ml_nobin = p_ml_nobin;
9245 buf->b_p_inf = p_inf;
9246 buf->b_p_swf = p_swf;
9247#ifdef FEAT_INS_EXPAND
9248 buf->b_p_cpt = vim_strsave(p_cpt);
9249#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009250#ifdef FEAT_COMPL_FUNC
9251 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009252 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009254 buf->b_p_sts = p_sts;
9255 buf->b_p_sts_nopaste = p_sts_nopaste;
9256#ifndef SHORT_FNAME
9257 buf->b_p_sn = p_sn;
9258#endif
9259#ifdef FEAT_COMMENTS
9260 buf->b_p_com = vim_strsave(p_com);
9261#endif
9262#ifdef FEAT_FOLDING
9263 buf->b_p_cms = vim_strsave(p_cms);
9264#endif
9265 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009266 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009267 buf->b_p_nf = vim_strsave(p_nf);
9268 buf->b_p_mps = vim_strsave(p_mps);
9269#ifdef FEAT_SMARTINDENT
9270 buf->b_p_si = p_si;
9271#endif
9272 buf->b_p_ci = p_ci;
9273#ifdef FEAT_CINDENT
9274 buf->b_p_cin = p_cin;
9275 buf->b_p_cink = vim_strsave(p_cink);
9276 buf->b_p_cino = vim_strsave(p_cino);
9277#endif
9278#ifdef FEAT_AUTOCMD
9279 /* Don't copy 'filetype', it must be detected */
9280 buf->b_p_ft = empty_option;
9281#endif
9282#ifdef FEAT_OSFILETYPE
9283 buf->b_p_oft = vim_strsave(p_oft);
9284#endif
9285 buf->b_p_pi = p_pi;
9286#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9287 buf->b_p_cinw = vim_strsave(p_cinw);
9288#endif
9289#ifdef FEAT_LISP
9290 buf->b_p_lisp = p_lisp;
9291#endif
9292#ifdef FEAT_SYN_HL
9293 /* Don't copy 'syntax', it must be set */
9294 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009295 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009296#endif
9297#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009298 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009299 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009300 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009301 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009302#endif
9303#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9304 buf->b_p_inde = vim_strsave(p_inde);
9305 buf->b_p_indk = vim_strsave(p_indk);
9306#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009307#if defined(FEAT_EVAL)
9308 buf->b_p_fex = vim_strsave(p_fex);
9309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310#ifdef FEAT_CRYPT
9311 buf->b_p_key = vim_strsave(p_key);
9312#endif
9313#ifdef FEAT_SEARCHPATH
9314 buf->b_p_sua = vim_strsave(p_sua);
9315#endif
9316#ifdef FEAT_KEYMAP
9317 buf->b_p_keymap = vim_strsave(p_keymap);
9318 buf->b_kmap_state |= KEYMAP_INIT;
9319#endif
9320 /* This isn't really an option, but copying the langmap and IME
9321 * state from the current buffer is better than resetting it. */
9322 buf->b_p_iminsert = p_iminsert;
9323 buf->b_p_imsearch = p_imsearch;
9324
9325 /* options that are normally global but also have a local value
9326 * are not copied, start using the global value */
9327 buf->b_p_ar = -1;
9328#ifdef FEAT_QUICKFIX
9329 buf->b_p_gp = empty_option;
9330 buf->b_p_mp = empty_option;
9331 buf->b_p_efm = empty_option;
9332#endif
9333 buf->b_p_ep = empty_option;
9334 buf->b_p_kp = empty_option;
9335 buf->b_p_path = empty_option;
9336 buf->b_p_tags = empty_option;
9337#ifdef FEAT_FIND_ID
9338 buf->b_p_def = empty_option;
9339 buf->b_p_inc = empty_option;
9340# ifdef FEAT_EVAL
9341 buf->b_p_inex = vim_strsave(p_inex);
9342# endif
9343#endif
9344#ifdef FEAT_INS_EXPAND
9345 buf->b_p_dict = empty_option;
9346 buf->b_p_tsr = empty_option;
9347#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009348#ifdef FEAT_TEXTOBJ
9349 buf->b_p_qe = vim_strsave(p_qe);
9350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351
9352 /*
9353 * Don't copy the options set by ex_help(), use the saved values,
9354 * when going from a help buffer to a non-help buffer.
9355 * Don't touch these at all when BCO_NOHELP is used and going from
9356 * or to a help buffer.
9357 */
9358 if (dont_do_help)
9359 buf->b_p_isk = save_p_isk;
9360 else
9361 {
9362 buf->b_p_isk = vim_strsave(p_isk);
9363 did_isk = TRUE;
9364 buf->b_p_ts = p_ts;
9365 buf->b_help = FALSE;
9366#ifdef FEAT_QUICKFIX
9367 if (buf->b_p_bt[0] == 'h')
9368 clear_string_option(&buf->b_p_bt);
9369#endif
9370 buf->b_p_ma = p_ma;
9371 }
9372 }
9373
9374 /*
9375 * When the options should be copied (ignoring BCO_ALWAYS), set the
9376 * flag that indicates that the options have been initialized.
9377 */
9378 if (should_copy)
9379 buf->b_p_initialized = TRUE;
9380 }
9381
9382 check_buf_options(buf); /* make sure we don't have NULLs */
9383 if (did_isk)
9384 (void)buf_init_chartab(buf, FALSE);
9385}
9386
9387/*
9388 * Reset the 'modifiable' option and its default value.
9389 */
9390 void
9391reset_modifiable()
9392{
9393 int opt_idx;
9394
9395 curbuf->b_p_ma = FALSE;
9396 p_ma = FALSE;
9397 opt_idx = findoption((char_u *)"ma");
9398 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9399}
9400
9401/*
9402 * Set the global value for 'iminsert' to the local value.
9403 */
9404 void
9405set_iminsert_global()
9406{
9407 p_iminsert = curbuf->b_p_iminsert;
9408}
9409
9410/*
9411 * Set the global value for 'imsearch' to the local value.
9412 */
9413 void
9414set_imsearch_global()
9415{
9416 p_imsearch = curbuf->b_p_imsearch;
9417}
9418
9419#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9420static int expand_option_idx = -1;
9421static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9422static int expand_option_flags = 0;
9423
9424 void
9425set_context_in_set_cmd(xp, arg, opt_flags)
9426 expand_T *xp;
9427 char_u *arg;
9428 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9429{
9430 int nextchar;
9431 long_u flags = 0; /* init for GCC */
9432 int opt_idx = 0; /* init for GCC */
9433 char_u *p;
9434 char_u *s;
9435 int is_term_option = FALSE;
9436 int key;
9437
9438 expand_option_flags = opt_flags;
9439
9440 xp->xp_context = EXPAND_SETTINGS;
9441 if (*arg == NUL)
9442 {
9443 xp->xp_pattern = arg;
9444 return;
9445 }
9446 p = arg + STRLEN(arg) - 1;
9447 if (*p == ' ' && *(p - 1) != '\\')
9448 {
9449 xp->xp_pattern = p + 1;
9450 return;
9451 }
9452 while (p > arg)
9453 {
9454 s = p;
9455 /* count number of backslashes before ' ' or ',' */
9456 if (*p == ' ' || *p == ',')
9457 {
9458 while (s > arg && *(s - 1) == '\\')
9459 --s;
9460 }
9461 /* break at a space with an even number of backslashes */
9462 if (*p == ' ' && ((p - s) & 1) == 0)
9463 {
9464 ++p;
9465 break;
9466 }
9467 --p;
9468 }
9469 if (STRNCMP(p, "no", 2) == 0)
9470 {
9471 xp->xp_context = EXPAND_BOOL_SETTINGS;
9472 p += 2;
9473 }
9474 if (STRNCMP(p, "inv", 3) == 0)
9475 {
9476 xp->xp_context = EXPAND_BOOL_SETTINGS;
9477 p += 3;
9478 }
9479 xp->xp_pattern = arg = p;
9480 if (*arg == '<')
9481 {
9482 while (*p != '>')
9483 if (*p++ == NUL) /* expand terminal option name */
9484 return;
9485 key = get_special_key_code(arg + 1);
9486 if (key == 0) /* unknown name */
9487 {
9488 xp->xp_context = EXPAND_NOTHING;
9489 return;
9490 }
9491 nextchar = *++p;
9492 is_term_option = TRUE;
9493 expand_option_name[2] = KEY2TERMCAP0(key);
9494 expand_option_name[3] = KEY2TERMCAP1(key);
9495 }
9496 else
9497 {
9498 if (p[0] == 't' && p[1] == '_')
9499 {
9500 p += 2;
9501 if (*p != NUL)
9502 ++p;
9503 if (*p == NUL)
9504 return; /* expand option name */
9505 nextchar = *++p;
9506 is_term_option = TRUE;
9507 expand_option_name[2] = p[-2];
9508 expand_option_name[3] = p[-1];
9509 }
9510 else
9511 {
9512 /* Allow * wildcard */
9513 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9514 p++;
9515 if (*p == NUL)
9516 return;
9517 nextchar = *p;
9518 *p = NUL;
9519 opt_idx = findoption(arg);
9520 *p = nextchar;
9521 if (opt_idx == -1 || options[opt_idx].var == NULL)
9522 {
9523 xp->xp_context = EXPAND_NOTHING;
9524 return;
9525 }
9526 flags = options[opt_idx].flags;
9527 if (flags & P_BOOL)
9528 {
9529 xp->xp_context = EXPAND_NOTHING;
9530 return;
9531 }
9532 }
9533 }
9534 /* handle "-=" and "+=" */
9535 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9536 {
9537 ++p;
9538 nextchar = '=';
9539 }
9540 if ((nextchar != '=' && nextchar != ':')
9541 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9542 {
9543 xp->xp_context = EXPAND_UNSUCCESSFUL;
9544 return;
9545 }
9546 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9547 {
9548 xp->xp_context = EXPAND_OLD_SETTING;
9549 if (is_term_option)
9550 expand_option_idx = -1;
9551 else
9552 expand_option_idx = opt_idx;
9553 xp->xp_pattern = p + 1;
9554 return;
9555 }
9556 xp->xp_context = EXPAND_NOTHING;
9557 if (is_term_option || (flags & P_NUM))
9558 return;
9559
9560 xp->xp_pattern = p + 1;
9561
9562 if (flags & P_EXPAND)
9563 {
9564 p = options[opt_idx].var;
9565 if (p == (char_u *)&p_bdir
9566 || p == (char_u *)&p_dir
9567 || p == (char_u *)&p_path
9568 || p == (char_u *)&p_rtp
9569#ifdef FEAT_SEARCHPATH
9570 || p == (char_u *)&p_cdpath
9571#endif
9572#ifdef FEAT_SESSION
9573 || p == (char_u *)&p_vdir
9574#endif
9575 )
9576 {
9577 xp->xp_context = EXPAND_DIRECTORIES;
9578 if (p == (char_u *)&p_path
9579#ifdef FEAT_SEARCHPATH
9580 || p == (char_u *)&p_cdpath
9581#endif
9582 )
9583 xp->xp_backslash = XP_BS_THREE;
9584 else
9585 xp->xp_backslash = XP_BS_ONE;
9586 }
9587 else
9588 {
9589 xp->xp_context = EXPAND_FILES;
9590 /* for 'tags' need three backslashes for a space */
9591 if (p == (char_u *)&p_tags)
9592 xp->xp_backslash = XP_BS_THREE;
9593 else
9594 xp->xp_backslash = XP_BS_ONE;
9595 }
9596 }
9597
9598 /* For an option that is a list of file names, find the start of the
9599 * last file name. */
9600 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9601 {
9602 /* count number of backslashes before ' ' or ',' */
9603 if (*p == ' ' || *p == ',')
9604 {
9605 s = p;
9606 while (s > xp->xp_pattern && *(s - 1) == '\\')
9607 --s;
9608 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9609 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9610 {
9611 xp->xp_pattern = p + 1;
9612 break;
9613 }
9614 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009615
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009616#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009617 /* for 'spellsuggest' start at "file:" */
9618 if (options[opt_idx].var == (char_u *)&p_sps
9619 && STRNCMP(p, "file:", 5) == 0)
9620 {
9621 xp->xp_pattern = p + 5;
9622 break;
9623 }
9624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625 }
9626
9627 return;
9628}
9629
9630 int
9631ExpandSettings(xp, regmatch, num_file, file)
9632 expand_T *xp;
9633 regmatch_T *regmatch;
9634 int *num_file;
9635 char_u ***file;
9636{
9637 int num_normal = 0; /* Nr of matching non-term-code settings */
9638 int num_term = 0; /* Nr of matching terminal code settings */
9639 int opt_idx;
9640 int match;
9641 int count = 0;
9642 char_u *str;
9643 int loop;
9644 int is_term_opt;
9645 char_u name_buf[MAX_KEY_NAME_LEN];
9646 static char *(names[]) = {"all", "termcap"};
9647 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9648
9649 /* do this loop twice:
9650 * loop == 0: count the number of matching options
9651 * loop == 1: copy the matching options into allocated memory
9652 */
9653 for (loop = 0; loop <= 1; ++loop)
9654 {
9655 regmatch->rm_ic = ic;
9656 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9657 {
9658 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9659 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9660 {
9661 if (loop == 0)
9662 num_normal++;
9663 else
9664 (*file)[count++] = vim_strsave((char_u *)names[match]);
9665 }
9666 }
9667 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9668 opt_idx++)
9669 {
9670 if (options[opt_idx].var == NULL)
9671 continue;
9672 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9673 && !(options[opt_idx].flags & P_BOOL))
9674 continue;
9675 is_term_opt = istermoption(&options[opt_idx]);
9676 if (is_term_opt && num_normal > 0)
9677 continue;
9678 match = FALSE;
9679 if (vim_regexec(regmatch, str, (colnr_T)0)
9680 || (options[opt_idx].shortname != NULL
9681 && vim_regexec(regmatch,
9682 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9683 match = TRUE;
9684 else if (is_term_opt)
9685 {
9686 name_buf[0] = '<';
9687 name_buf[1] = 't';
9688 name_buf[2] = '_';
9689 name_buf[3] = str[2];
9690 name_buf[4] = str[3];
9691 name_buf[5] = '>';
9692 name_buf[6] = NUL;
9693 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9694 {
9695 match = TRUE;
9696 str = name_buf;
9697 }
9698 }
9699 if (match)
9700 {
9701 if (loop == 0)
9702 {
9703 if (is_term_opt)
9704 num_term++;
9705 else
9706 num_normal++;
9707 }
9708 else
9709 (*file)[count++] = vim_strsave(str);
9710 }
9711 }
9712 /*
9713 * Check terminal key codes, these are not in the option table
9714 */
9715 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9716 {
9717 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9718 {
9719 if (!isprint(str[0]) || !isprint(str[1]))
9720 continue;
9721
9722 name_buf[0] = 't';
9723 name_buf[1] = '_';
9724 name_buf[2] = str[0];
9725 name_buf[3] = str[1];
9726 name_buf[4] = NUL;
9727
9728 match = FALSE;
9729 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9730 match = TRUE;
9731 else
9732 {
9733 name_buf[0] = '<';
9734 name_buf[1] = 't';
9735 name_buf[2] = '_';
9736 name_buf[3] = str[0];
9737 name_buf[4] = str[1];
9738 name_buf[5] = '>';
9739 name_buf[6] = NUL;
9740
9741 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9742 match = TRUE;
9743 }
9744 if (match)
9745 {
9746 if (loop == 0)
9747 num_term++;
9748 else
9749 (*file)[count++] = vim_strsave(name_buf);
9750 }
9751 }
9752
9753 /*
9754 * Check special key names.
9755 */
9756 regmatch->rm_ic = TRUE; /* ignore case here */
9757 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9758 {
9759 name_buf[0] = '<';
9760 STRCPY(name_buf + 1, str);
9761 STRCAT(name_buf, ">");
9762
9763 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9764 {
9765 if (loop == 0)
9766 num_term++;
9767 else
9768 (*file)[count++] = vim_strsave(name_buf);
9769 }
9770 }
9771 }
9772 if (loop == 0)
9773 {
9774 if (num_normal > 0)
9775 *num_file = num_normal;
9776 else if (num_term > 0)
9777 *num_file = num_term;
9778 else
9779 return OK;
9780 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9781 if (*file == NULL)
9782 {
9783 *file = (char_u **)"";
9784 return FAIL;
9785 }
9786 }
9787 }
9788 return OK;
9789}
9790
9791 int
9792ExpandOldSetting(num_file, file)
9793 int *num_file;
9794 char_u ***file;
9795{
9796 char_u *var = NULL; /* init for GCC */
9797 char_u *buf;
9798
9799 *num_file = 0;
9800 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9801 if (*file == NULL)
9802 return FAIL;
9803
9804 /*
9805 * For a terminal key code expand_option_idx is < 0.
9806 */
9807 if (expand_option_idx < 0)
9808 {
9809 var = find_termcode(expand_option_name + 2);
9810 if (var == NULL)
9811 expand_option_idx = findoption(expand_option_name);
9812 }
9813
9814 if (expand_option_idx >= 0)
9815 {
9816 /* put string of option value in NameBuff */
9817 option_value2string(&options[expand_option_idx], expand_option_flags);
9818 var = NameBuff;
9819 }
9820 else if (var == NULL)
9821 var = (char_u *)"";
9822
9823 /* A backslash is required before some characters. This is the reverse of
9824 * what happens in do_set(). */
9825 buf = vim_strsave_escaped(var, escape_chars);
9826
9827 if (buf == NULL)
9828 {
9829 vim_free(*file);
9830 *file = NULL;
9831 return FAIL;
9832 }
9833
9834#ifdef BACKSLASH_IN_FILENAME
9835 /* For MS-Windows et al. we don't double backslashes at the start and
9836 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009837 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838 if (var[0] == '\\' && var[1] == '\\'
9839 && expand_option_idx >= 0
9840 && (options[expand_option_idx].flags & P_EXPAND)
9841 && vim_isfilec(var[2])
9842 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9843 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844#endif
9845
9846 *file[0] = buf;
9847 *num_file = 1;
9848 return OK;
9849}
9850#endif
9851
9852/*
9853 * Get the value for the numeric or string option *opp in a nice format into
9854 * NameBuff[]. Must not be called with a hidden option!
9855 */
9856 static void
9857option_value2string(opp, opt_flags)
9858 struct vimoption *opp;
9859 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9860{
9861 char_u *varp;
9862
9863 varp = get_varp_scope(opp, opt_flags);
9864
9865 if (opp->flags & P_NUM)
9866 {
9867 long wc = 0;
9868
9869 if (wc_use_keyname(varp, &wc))
9870 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9871 else if (wc != 0)
9872 STRCPY(NameBuff, transchar((int)wc));
9873 else
9874 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9875 }
9876 else /* P_STRING */
9877 {
9878 varp = *(char_u **)(varp);
9879 if (varp == NULL) /* just in case */
9880 NameBuff[0] = NUL;
9881#ifdef FEAT_CRYPT
9882 /* don't show the actual value of 'key', only that it's set */
9883 if (opp->var == (char_u *)&p_key && *varp)
9884 STRCPY(NameBuff, "*****");
9885#endif
9886 else if (opp->flags & P_EXPAND)
9887 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9888 /* Translate 'pastetoggle' into special key names */
9889 else if ((char_u **)opp->var == &p_pt)
9890 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9891 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009892 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009893 }
9894}
9895
9896/*
9897 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9898 * printed as a keyname.
9899 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9900 */
9901 static int
9902wc_use_keyname(varp, wcp)
9903 char_u *varp;
9904 long *wcp;
9905{
9906 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9907 {
9908 *wcp = *(long *)varp;
9909 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9910 return TRUE;
9911 }
9912 return FALSE;
9913}
9914
9915#ifdef FEAT_LANGMAP
9916/*
9917 * Any character has an equivalent character. This is used for keyboards that
9918 * have a special language mode that sends characters above 128 (although
9919 * other characters can be translated too).
9920 */
9921
9922/*
9923 * char_u langmap_mapchar[256];
9924 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9925 * "translate" native lang chars in normal mode or some cases of
9926 * insert mode without having to tediously switch lang mode back&forth.
9927 */
9928
9929 static void
9930langmap_init()
9931{
9932 int i;
9933
9934 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9935 langmap_mapchar[i] = i;
9936}
9937
9938/*
9939 * Called when langmap option is set; the language map can be
9940 * changed at any time!
9941 */
9942 static void
9943langmap_set()
9944{
9945 char_u *p;
9946 char_u *p2;
9947 int from, to;
9948
9949 langmap_init(); /* back to one-to-one map first */
9950
9951 for (p = p_langmap; p[0] != NUL; )
9952 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009953 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9954 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 {
9956 if (p2[0] == '\\' && p2[1] != NUL)
9957 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958 }
9959 if (p2[0] == ';')
9960 ++p2; /* abcd;ABCD form, p2 points to A */
9961 else
9962 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9963 while (p[0])
9964 {
9965 if (p[0] == '\\' && p[1] != NUL)
9966 ++p;
9967#ifdef FEAT_MBYTE
9968 from = (*mb_ptr2char)(p);
9969#else
9970 from = p[0];
9971#endif
9972 if (p2 == NULL)
9973 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009974 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975 if (p[0] == '\\')
9976 ++p;
9977#ifdef FEAT_MBYTE
9978 to = (*mb_ptr2char)(p);
9979#else
9980 to = p[0];
9981#endif
9982 }
9983 else
9984 {
9985 if (p2[0] == '\\')
9986 ++p2;
9987#ifdef FEAT_MBYTE
9988 to = (*mb_ptr2char)(p2);
9989#else
9990 to = p2[0];
9991#endif
9992 }
9993 if (to == NUL)
9994 {
9995 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9996 transchar(from));
9997 return;
9998 }
9999 langmap_mapchar[from & 255] = to;
10000
10001 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010002 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003 if (p2 == NULL)
10004 {
10005 if (p[0] == ',')
10006 {
10007 ++p;
10008 break;
10009 }
10010 }
10011 else
10012 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010013 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014 if (*p == ';')
10015 {
10016 p = p2;
10017 if (p[0] != NUL)
10018 {
10019 if (p[0] != ',')
10020 {
10021 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10022 return;
10023 }
10024 ++p;
10025 }
10026 break;
10027 }
10028 }
10029 }
10030 }
10031}
10032#endif
10033
10034/*
10035 * Return TRUE if format option 'x' is in effect.
10036 * Take care of no formatting when 'paste' is set.
10037 */
10038 int
10039has_format_option(x)
10040 int x;
10041{
10042 if (p_paste)
10043 return FALSE;
10044 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10045}
10046
10047/*
10048 * Return TRUE if "x" is present in 'shortmess' option, or
10049 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10050 */
10051 int
10052shortmess(x)
10053 int x;
10054{
10055 return ( vim_strchr(p_shm, x) != NULL
10056 || (vim_strchr(p_shm, 'a') != NULL
10057 && vim_strchr((char_u *)SHM_A, x) != NULL));
10058}
10059
10060/*
10061 * paste_option_changed() - Called after p_paste was set or reset.
10062 */
10063 static void
10064paste_option_changed()
10065{
10066 static int old_p_paste = FALSE;
10067 static int save_sm = 0;
10068#ifdef FEAT_CMDL_INFO
10069 static int save_ru = 0;
10070#endif
10071#ifdef FEAT_RIGHTLEFT
10072 static int save_ri = 0;
10073 static int save_hkmap = 0;
10074#endif
10075 buf_T *buf;
10076
10077 if (p_paste)
10078 {
10079 /*
10080 * Paste switched from off to on.
10081 * Save the current values, so they can be restored later.
10082 */
10083 if (!old_p_paste)
10084 {
10085 /* save options for each buffer */
10086 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10087 {
10088 buf->b_p_tw_nopaste = buf->b_p_tw;
10089 buf->b_p_wm_nopaste = buf->b_p_wm;
10090 buf->b_p_sts_nopaste = buf->b_p_sts;
10091 buf->b_p_ai_nopaste = buf->b_p_ai;
10092 }
10093
10094 /* save global options */
10095 save_sm = p_sm;
10096#ifdef FEAT_CMDL_INFO
10097 save_ru = p_ru;
10098#endif
10099#ifdef FEAT_RIGHTLEFT
10100 save_ri = p_ri;
10101 save_hkmap = p_hkmap;
10102#endif
10103 /* save global values for local buffer options */
10104 p_tw_nopaste = p_tw;
10105 p_wm_nopaste = p_wm;
10106 p_sts_nopaste = p_sts;
10107 p_ai_nopaste = p_ai;
10108 }
10109
10110 /*
10111 * Always set the option values, also when 'paste' is set when it is
10112 * already on.
10113 */
10114 /* set options for each buffer */
10115 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10116 {
10117 buf->b_p_tw = 0; /* textwidth is 0 */
10118 buf->b_p_wm = 0; /* wrapmargin is 0 */
10119 buf->b_p_sts = 0; /* softtabstop is 0 */
10120 buf->b_p_ai = 0; /* no auto-indent */
10121 }
10122
10123 /* set global options */
10124 p_sm = 0; /* no showmatch */
10125#ifdef FEAT_CMDL_INFO
10126# ifdef FEAT_WINDOWS
10127 if (p_ru)
10128 status_redraw_all(); /* redraw to remove the ruler */
10129# endif
10130 p_ru = 0; /* no ruler */
10131#endif
10132#ifdef FEAT_RIGHTLEFT
10133 p_ri = 0; /* no reverse insert */
10134 p_hkmap = 0; /* no Hebrew keyboard */
10135#endif
10136 /* set global values for local buffer options */
10137 p_tw = 0;
10138 p_wm = 0;
10139 p_sts = 0;
10140 p_ai = 0;
10141 }
10142
10143 /*
10144 * Paste switched from on to off: Restore saved values.
10145 */
10146 else if (old_p_paste)
10147 {
10148 /* restore options for each buffer */
10149 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10150 {
10151 buf->b_p_tw = buf->b_p_tw_nopaste;
10152 buf->b_p_wm = buf->b_p_wm_nopaste;
10153 buf->b_p_sts = buf->b_p_sts_nopaste;
10154 buf->b_p_ai = buf->b_p_ai_nopaste;
10155 }
10156
10157 /* restore global options */
10158 p_sm = save_sm;
10159#ifdef FEAT_CMDL_INFO
10160# ifdef FEAT_WINDOWS
10161 if (p_ru != save_ru)
10162 status_redraw_all(); /* redraw to draw the ruler */
10163# endif
10164 p_ru = save_ru;
10165#endif
10166#ifdef FEAT_RIGHTLEFT
10167 p_ri = save_ri;
10168 p_hkmap = save_hkmap;
10169#endif
10170 /* set global values for local buffer options */
10171 p_tw = p_tw_nopaste;
10172 p_wm = p_wm_nopaste;
10173 p_sts = p_sts_nopaste;
10174 p_ai = p_ai_nopaste;
10175 }
10176
10177 old_p_paste = p_paste;
10178}
10179
10180/*
10181 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10182 *
10183 * Reset 'compatible' and set the values for options that didn't get set yet
10184 * to the Vim defaults.
10185 * Don't do this if the 'compatible' option has been set or reset before.
10186 */
10187 void
10188vimrc_found()
10189{
10190 int opt_idx;
10191
10192 if (!option_was_set((char_u *)"cp"))
10193 {
10194 p_cp = FALSE;
10195 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10196 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10197 set_option_default(opt_idx, OPT_FREE, FALSE);
10198 didset_options();
10199 }
10200}
10201
10202/*
10203 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10204 */
10205 void
10206change_compatible(on)
10207 int on;
10208{
10209 if (p_cp != on)
10210 {
10211 p_cp = on;
10212 compatible_set();
10213 }
10214 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
10215}
10216
10217/*
10218 * Return TRUE when option "name" has been set.
10219 */
10220 int
10221option_was_set(name)
10222 char_u *name;
10223{
10224 int idx;
10225
10226 idx = findoption(name);
10227 if (idx < 0) /* unknown option */
10228 return FALSE;
10229 if (options[idx].flags & P_WAS_SET)
10230 return TRUE;
10231 return FALSE;
10232}
10233
10234/*
10235 * compatible_set() - Called when 'compatible' has been set or unset.
10236 *
10237 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10238 * flag) to a Vi compatible value.
10239 * When 'compatible' is unset: Set all options that have a different default
10240 * for Vim (without the P_VI_DEF flag) to that default.
10241 */
10242 static void
10243compatible_set()
10244{
10245 int opt_idx;
10246
10247 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10248 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10249 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10250 set_option_default(opt_idx, OPT_FREE, p_cp);
10251 didset_options();
10252}
10253
10254#ifdef FEAT_LINEBREAK
10255
10256# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10257 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010258 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259# endif
10260
10261/*
10262 * fill_breakat_flags() -- called when 'breakat' changes value.
10263 */
10264 static void
10265fill_breakat_flags()
10266{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010267 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 int i;
10269
10270 for (i = 0; i < 256; i++)
10271 breakat_flags[i] = FALSE;
10272
10273 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010274 for (p = p_breakat; *p; p++)
10275 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276}
10277
10278# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010279 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280# endif
10281
10282#endif
10283
10284/*
10285 * Check an option that can be a range of string values.
10286 *
10287 * Return OK for correct value, FAIL otherwise.
10288 * Empty is always OK.
10289 */
10290 static int
10291check_opt_strings(val, values, list)
10292 char_u *val;
10293 char **values;
10294 int list; /* when TRUE: accept a list of values */
10295{
10296 return opt_strings_flags(val, values, NULL, list);
10297}
10298
10299/*
10300 * Handle an option that can be a range of string values.
10301 * Set a flag in "*flagp" for each string present.
10302 *
10303 * Return OK for correct value, FAIL otherwise.
10304 * Empty is always OK.
10305 */
10306 static int
10307opt_strings_flags(val, values, flagp, list)
10308 char_u *val; /* new value */
10309 char **values; /* array of valid string values */
10310 unsigned *flagp;
10311 int list; /* when TRUE: accept a list of values */
10312{
10313 int i;
10314 int len;
10315 unsigned new_flags = 0;
10316
10317 while (*val)
10318 {
10319 for (i = 0; ; ++i)
10320 {
10321 if (values[i] == NULL) /* val not found in values[] */
10322 return FAIL;
10323
10324 len = (int)STRLEN(values[i]);
10325 if (STRNCMP(values[i], val, len) == 0
10326 && ((list && val[len] == ',') || val[len] == NUL))
10327 {
10328 val += len + (val[len] == ',');
10329 new_flags |= (1 << i);
10330 break; /* check next item in val list */
10331 }
10332 }
10333 }
10334 if (flagp != NULL)
10335 *flagp = new_flags;
10336
10337 return OK;
10338}
10339
10340/*
10341 * Read the 'wildmode' option, fill wim_flags[].
10342 */
10343 static int
10344check_opt_wim()
10345{
10346 char_u new_wim_flags[4];
10347 char_u *p;
10348 int i;
10349 int idx = 0;
10350
10351 for (i = 0; i < 4; ++i)
10352 new_wim_flags[i] = 0;
10353
10354 for (p = p_wim; *p; ++p)
10355 {
10356 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10357 ;
10358 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10359 return FAIL;
10360 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10361 new_wim_flags[idx] |= WIM_LONGEST;
10362 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10363 new_wim_flags[idx] |= WIM_FULL;
10364 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10365 new_wim_flags[idx] |= WIM_LIST;
10366 else
10367 return FAIL;
10368 p += i;
10369 if (*p == NUL)
10370 break;
10371 if (*p == ',')
10372 {
10373 if (idx == 3)
10374 return FAIL;
10375 ++idx;
10376 }
10377 }
10378
10379 /* fill remaining entries with last flag */
10380 while (idx < 3)
10381 {
10382 new_wim_flags[idx + 1] = new_wim_flags[idx];
10383 ++idx;
10384 }
10385
10386 /* only when there are no errors, wim_flags[] is changed */
10387 for (i = 0; i < 4; ++i)
10388 wim_flags[i] = new_wim_flags[i];
10389 return OK;
10390}
10391
10392/*
10393 * Check if backspacing over something is allowed.
10394 */
10395 int
10396can_bs(what)
10397 int what; /* BS_INDENT, BS_EOL or BS_START */
10398{
10399 switch (*p_bs)
10400 {
10401 case '2': return TRUE;
10402 case '1': return (what != BS_START);
10403 case '0': return FALSE;
10404 }
10405 return vim_strchr(p_bs, what) != NULL;
10406}
10407
10408/*
10409 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10410 * the file must be considered changed when the value is different.
10411 */
10412 void
10413save_file_ff(buf)
10414 buf_T *buf;
10415{
10416 buf->b_start_ffc = *buf->b_p_ff;
10417 buf->b_start_eol = buf->b_p_eol;
10418#ifdef FEAT_MBYTE
10419 /* Only use free/alloc when necessary, they take time. */
10420 if (buf->b_start_fenc == NULL
10421 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10422 {
10423 vim_free(buf->b_start_fenc);
10424 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10425 }
10426#endif
10427}
10428
10429/*
10430 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10431 * from when editing started (save_file_ff() called).
10432 * Also when 'endofline' was changed and 'binary' is set.
10433 * Don't consider a new, empty buffer to be changed.
10434 */
10435 int
10436file_ff_differs(buf)
10437 buf_T *buf;
10438{
10439 if ((buf->b_flags & BF_NEW)
10440 && buf->b_ml.ml_line_count == 1
10441 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10442 return FALSE;
10443 if (buf->b_start_ffc != *buf->b_p_ff)
10444 return TRUE;
10445 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10446 return TRUE;
10447#ifdef FEAT_MBYTE
10448 if (buf->b_start_fenc == NULL)
10449 return (*buf->b_p_fenc != NUL);
10450 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10451#else
10452 return FALSE;
10453#endif
10454}
10455
10456/*
10457 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10458 */
10459 int
10460check_ff_value(p)
10461 char_u *p;
10462{
10463 return check_opt_strings(p, p_ff_values, FALSE);
10464}