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