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