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