blob: 23b6be81e8d17d76a47bfc3bb92f653252597a0c [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 Moolenaarfd2ac762006-03-01 22:09:21 +00002298 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2299#ifdef FEAT_WINDOWS
2300 (char_u *)&p_tpm, PV_NONE,
2301#else
2302 (char_u *)NULL, PV_NONE,
2303#endif
2304 {(char_u *)10L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2306 (char_u *)&p_ts, PV_TS,
2307 {(char_u *)8L, (char_u *)0L}},
2308 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2309 (char_u *)&p_tbs, PV_NONE,
2310#ifdef VMS /* binary searching doesn't appear to work on VMS */
2311 {(char_u *)0L, (char_u *)0L}
2312#else
2313 {(char_u *)TRUE, (char_u *)0L}
2314#endif
2315 },
2316 {"taglength", "tl", P_NUM|P_VI_DEF,
2317 (char_u *)&p_tl, PV_NONE,
2318 {(char_u *)0L, (char_u *)0L}},
2319 {"tagrelative", "tr", P_BOOL|P_VIM,
2320 (char_u *)&p_tr, PV_NONE,
2321 {(char_u *)FALSE, (char_u *)TRUE}},
2322 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002323 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {
2325#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2326 (char_u *)"./tags,./TAGS,tags,TAGS",
2327#else
2328 (char_u *)"./tags,tags",
2329#endif
2330 (char_u *)0L}},
2331 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2332 (char_u *)&p_tgst, PV_NONE,
2333 {(char_u *)TRUE, (char_u *)0L}},
2334 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2335 (char_u *)&T_NAME, PV_NONE,
2336 {(char_u *)"", (char_u *)0L}},
2337 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2338#ifdef FEAT_ARABIC
2339 (char_u *)&p_tbidi, PV_NONE,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
2343 {(char_u *)FALSE, (char_u *)0L}},
2344 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2345#ifdef FEAT_MBYTE
2346 (char_u *)&p_tenc, PV_NONE,
2347 {(char_u *)"", (char_u *)0L}
2348#else
2349 (char_u *)NULL, PV_NONE,
2350 {(char_u *)0L, (char_u *)0L}
2351#endif
2352 },
2353 {"terse", NULL, P_BOOL|P_VI_DEF,
2354 (char_u *)&p_terse, PV_NONE,
2355 {(char_u *)FALSE, (char_u *)0L}},
2356 {"textauto", "ta", P_BOOL|P_VIM,
2357 (char_u *)&p_ta, PV_NONE,
2358 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2359 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2360 (char_u *)&p_tx, PV_TX,
2361 {
2362#ifdef USE_CRNL
2363 (char_u *)TRUE,
2364#else
2365 (char_u *)FALSE,
2366#endif
2367 (char_u *)0L}},
2368 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2369 (char_u *)&p_tw, PV_TW,
2370 {(char_u *)0L, (char_u *)0L}},
2371 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2372#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002373 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374#else
2375 (char_u *)NULL, PV_NONE,
2376#endif
2377 {(char_u *)"", (char_u *)0L}},
2378 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2379 (char_u *)&p_to, PV_NONE,
2380 {(char_u *)FALSE, (char_u *)0L}},
2381 {"timeout", "to", P_BOOL|P_VI_DEF,
2382 (char_u *)&p_timeout, PV_NONE,
2383 {(char_u *)TRUE, (char_u *)0L}},
2384 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2385 (char_u *)&p_tm, PV_NONE,
2386 {(char_u *)1000L, (char_u *)0L}},
2387 {"title", NULL, P_BOOL|P_VI_DEF,
2388#ifdef FEAT_TITLE
2389 (char_u *)&p_title, PV_NONE,
2390#else
2391 (char_u *)NULL, PV_NONE,
2392#endif
2393 {(char_u *)FALSE, (char_u *)0L}},
2394 {"titlelen", NULL, P_NUM|P_VI_DEF,
2395#ifdef FEAT_TITLE
2396 (char_u *)&p_titlelen, PV_NONE,
2397#else
2398 (char_u *)NULL, PV_NONE,
2399#endif
2400 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002401 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402#ifdef FEAT_TITLE
2403 (char_u *)&p_titleold, PV_NONE,
2404 {(char_u *)N_("Thanks for flying Vim"),
2405 (char_u *)0L}
2406#else
2407 (char_u *)NULL, PV_NONE,
2408 {(char_u *)0L, (char_u *)0L}
2409#endif
2410 },
2411 {"titlestring", NULL, P_STRING|P_VI_DEF,
2412#ifdef FEAT_TITLE
2413 (char_u *)&p_titlestring, PV_NONE,
2414#else
2415 (char_u *)NULL, PV_NONE,
2416#endif
2417 {(char_u *)"", (char_u *)0L}},
2418#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2419 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2420 (char_u *)&p_toolbar, PV_NONE,
2421 {(char_u *)"icons,tooltips", (char_u *)0L}},
2422#endif
2423#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2424 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2425 (char_u *)&p_tbis, PV_NONE,
2426 {(char_u *)"small", (char_u *)0L}},
2427#endif
2428 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2429 (char_u *)&p_ttimeout, PV_NONE,
2430 {(char_u *)FALSE, (char_u *)0L}},
2431 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2432 (char_u *)&p_ttm, PV_NONE,
2433 {(char_u *)-1L, (char_u *)0L}},
2434 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2435 (char_u *)&p_tbi, PV_NONE,
2436 {(char_u *)TRUE, (char_u *)0L}},
2437 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2438 (char_u *)&p_tf, PV_NONE,
2439 {(char_u *)FALSE, (char_u *)0L}},
2440 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2441#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2442 (char_u *)&p_ttym, PV_NONE,
2443#else
2444 (char_u *)NULL, PV_NONE,
2445#endif
2446 {(char_u *)"", (char_u *)0L}},
2447 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2448 (char_u *)&p_ttyscroll, PV_NONE,
2449 {(char_u *)999L, (char_u *)0L}},
2450 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2451 (char_u *)&T_NAME, PV_NONE,
2452 {(char_u *)"", (char_u *)0L}},
2453 {"undolevels", "ul", P_NUM|P_VI_DEF,
2454 (char_u *)&p_ul, PV_NONE,
2455 {
2456#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2457 (char_u *)1000L,
2458#else
2459 (char_u *)100L,
2460#endif
2461 (char_u *)0L}},
2462 {"updatecount", "uc", P_NUM|P_VI_DEF,
2463 (char_u *)&p_uc, PV_NONE,
2464 {(char_u *)200L, (char_u *)0L}},
2465 {"updatetime", "ut", P_NUM|P_VI_DEF,
2466 (char_u *)&p_ut, PV_NONE,
2467 {(char_u *)4000L, (char_u *)0L}},
2468 {"verbose", "vbs", P_NUM|P_VI_DEF,
2469 (char_u *)&p_verbose, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002471 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2472 (char_u *)&p_vfile, PV_NONE,
2473 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2475#ifdef FEAT_SESSION
2476 (char_u *)&p_vdir, PV_NONE,
2477 {(char_u *)DFLT_VDIR, (char_u *)0L}
2478#else
2479 (char_u *)NULL, PV_NONE,
2480 {(char_u *)0L, (char_u *)0L}
2481#endif
2482 },
2483 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2484#ifdef FEAT_SESSION
2485 (char_u *)&p_vop, PV_NONE,
2486 {(char_u *)"folds,options,cursor", (char_u *)0L}
2487#else
2488 (char_u *)NULL, PV_NONE,
2489 {(char_u *)0L, (char_u *)0L}
2490#endif
2491 },
2492 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2493#ifdef FEAT_VIMINFO
2494 (char_u *)&p_viminfo, PV_NONE,
2495#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2496 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2497#else
2498# ifdef AMIGA
2499 {(char_u *)"",
2500 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2501# else
2502 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2503# endif
2504#endif
2505#else
2506 (char_u *)NULL, PV_NONE,
2507 {(char_u *)0L, (char_u *)0L}
2508#endif
2509 },
2510 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2511#ifdef FEAT_VIRTUALEDIT
2512 (char_u *)&p_ve, PV_NONE,
2513 {(char_u *)"", (char_u *)""}
2514#else
2515 (char_u *)NULL, PV_NONE,
2516 {(char_u *)0L, (char_u *)0L}
2517#endif
2518 },
2519 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2520 (char_u *)&p_vb, PV_NONE,
2521 {(char_u *)FALSE, (char_u *)0L}},
2522 {"w300", NULL, P_NUM|P_VI_DEF,
2523 (char_u *)NULL, PV_NONE,
2524 {(char_u *)0L, (char_u *)0L}},
2525 {"w1200", NULL, P_NUM|P_VI_DEF,
2526 (char_u *)NULL, PV_NONE,
2527 {(char_u *)0L, (char_u *)0L}},
2528 {"w9600", NULL, P_NUM|P_VI_DEF,
2529 (char_u *)NULL, PV_NONE,
2530 {(char_u *)0L, (char_u *)0L}},
2531 {"warn", NULL, P_BOOL|P_VI_DEF,
2532 (char_u *)&p_warn, PV_NONE,
2533 {(char_u *)TRUE, (char_u *)0L}},
2534 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2535 (char_u *)&p_wiv, PV_NONE,
2536 {(char_u *)FALSE, (char_u *)0L}},
2537 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2538 (char_u *)&p_ww, PV_NONE,
2539 {(char_u *)"", (char_u *)"b,s"}},
2540 {"wildchar", "wc", P_NUM|P_VIM,
2541 (char_u *)&p_wc, PV_NONE,
2542 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2543 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2544 (char_u *)&p_wcm, PV_NONE,
2545 {(char_u *)0L, (char_u *)0L}},
2546 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2547#ifdef FEAT_WILDIGN
2548 (char_u *)&p_wig, PV_NONE,
2549#else
2550 (char_u *)NULL, PV_NONE,
2551#endif
2552 {(char_u *)"", (char_u *)0L}},
2553 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2554#ifdef FEAT_WILDMENU
2555 (char_u *)&p_wmnu, PV_NONE,
2556#else
2557 (char_u *)NULL, PV_NONE,
2558#endif
2559 {(char_u *)FALSE, (char_u *)0L}},
2560 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2561 (char_u *)&p_wim, PV_NONE,
2562 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002563 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2564#ifdef FEAT_CMDL_COMPL
2565 (char_u *)&p_wop, PV_NONE,
2566 {(char_u *)"", (char_u *)0L}
2567#else
2568 (char_u *)NULL, PV_NONE,
2569 {(char_u *)NULL, (char_u *)0L}
2570#endif
2571 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2573#ifdef FEAT_WAK
2574 (char_u *)&p_wak, PV_NONE,
2575 {(char_u *)"menu", (char_u *)0L}
2576#else
2577 (char_u *)NULL, PV_NONE,
2578 {(char_u *)NULL, (char_u *)0L}
2579#endif
2580 },
2581 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002582 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {(char_u *)0L, (char_u *)0L}},
2584 {"winheight", "wh", P_NUM|P_VI_DEF,
2585#ifdef FEAT_WINDOWS
2586 (char_u *)&p_wh, PV_NONE,
2587#else
2588 (char_u *)NULL, PV_NONE,
2589#endif
2590 {(char_u *)1L, (char_u *)0L}},
2591 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002592#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 (char_u *)VAR_WIN, PV_WFH,
2594#else
2595 (char_u *)NULL, PV_NONE,
2596#endif
2597 {(char_u *)FALSE, (char_u *)0L}},
2598 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2599#ifdef FEAT_WINDOWS
2600 (char_u *)&p_wmh, PV_NONE,
2601#else
2602 (char_u *)NULL, PV_NONE,
2603#endif
2604 {(char_u *)1L, (char_u *)0L}},
2605 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2606#ifdef FEAT_VERTSPLIT
2607 (char_u *)&p_wmw, PV_NONE,
2608#else
2609 (char_u *)NULL, PV_NONE,
2610#endif
2611 {(char_u *)1L, (char_u *)0L}},
2612 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2613#ifdef FEAT_VERTSPLIT
2614 (char_u *)&p_wiw, PV_NONE,
2615#else
2616 (char_u *)NULL, PV_NONE,
2617#endif
2618 {(char_u *)20L, (char_u *)0L}},
2619 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2620 (char_u *)VAR_WIN, PV_WRAP,
2621 {(char_u *)TRUE, (char_u *)0L}},
2622 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2623 (char_u *)&p_wm, PV_WM,
2624 {(char_u *)0L, (char_u *)0L}},
2625 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2626 (char_u *)&p_ws, PV_NONE,
2627 {(char_u *)TRUE, (char_u *)0L}},
2628 {"write", NULL, P_BOOL|P_VI_DEF,
2629 (char_u *)&p_write, PV_NONE,
2630 {(char_u *)TRUE, (char_u *)0L}},
2631 {"writeany", "wa", P_BOOL|P_VI_DEF,
2632 (char_u *)&p_wa, PV_NONE,
2633 {(char_u *)FALSE, (char_u *)0L}},
2634 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2635 (char_u *)&p_wb, PV_NONE,
2636 {
2637#ifdef FEAT_WRITEBACKUP
2638 (char_u *)TRUE,
2639#else
2640 (char_u *)FALSE,
2641#endif
2642 (char_u *)0L}},
2643 {"writedelay", "wd", P_NUM|P_VI_DEF,
2644 (char_u *)&p_wd, PV_NONE,
2645 {(char_u *)0L, (char_u *)0L}},
2646
2647/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002648#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 (char_u *)&vvv, PV_NONE, \
2650 {(char_u *)"", (char_u *)0L}},
2651
2652 p_term("t_AB", T_CAB)
2653 p_term("t_AF", T_CAF)
2654 p_term("t_AL", T_CAL)
2655 p_term("t_al", T_AL)
2656 p_term("t_bc", T_BC)
2657 p_term("t_cd", T_CD)
2658 p_term("t_ce", T_CE)
2659 p_term("t_cl", T_CL)
2660 p_term("t_cm", T_CM)
2661 p_term("t_Co", T_CCO)
2662 p_term("t_CS", T_CCS)
2663 p_term("t_cs", T_CS)
2664#ifdef FEAT_VERTSPLIT
2665 p_term("t_CV", T_CSV)
2666#endif
2667 p_term("t_ut", T_UT)
2668 p_term("t_da", T_DA)
2669 p_term("t_db", T_DB)
2670 p_term("t_DL", T_CDL)
2671 p_term("t_dl", T_DL)
2672 p_term("t_fs", T_FS)
2673 p_term("t_IE", T_CIE)
2674 p_term("t_IS", T_CIS)
2675 p_term("t_ke", T_KE)
2676 p_term("t_ks", T_KS)
2677 p_term("t_le", T_LE)
2678 p_term("t_mb", T_MB)
2679 p_term("t_md", T_MD)
2680 p_term("t_me", T_ME)
2681 p_term("t_mr", T_MR)
2682 p_term("t_ms", T_MS)
2683 p_term("t_nd", T_ND)
2684 p_term("t_op", T_OP)
2685 p_term("t_RI", T_CRI)
2686 p_term("t_RV", T_CRV)
2687 p_term("t_Sb", T_CSB)
2688 p_term("t_Sf", T_CSF)
2689 p_term("t_se", T_SE)
2690 p_term("t_so", T_SO)
2691 p_term("t_sr", T_SR)
2692 p_term("t_ts", T_TS)
2693 p_term("t_te", T_TE)
2694 p_term("t_ti", T_TI)
2695 p_term("t_ue", T_UE)
2696 p_term("t_us", T_US)
2697 p_term("t_vb", T_VB)
2698 p_term("t_ve", T_VE)
2699 p_term("t_vi", T_VI)
2700 p_term("t_vs", T_VS)
2701 p_term("t_WP", T_CWP)
2702 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002703 p_term("t_SI", T_CSI)
2704 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 p_term("t_xs", T_XS)
2706 p_term("t_ZH", T_CZH)
2707 p_term("t_ZR", T_CZR)
2708
2709/* terminal key codes are not in here */
2710
2711 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2712};
2713
2714#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2715
2716#ifdef FEAT_MBYTE
2717static char *(p_ambw_values[]) = {"single", "double", NULL};
2718#endif
2719static char *(p_bg_values[]) = {"light", "dark", NULL};
2720static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2721static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002722#ifdef FEAT_CMDL_COMPL
2723static char *(p_wop_values[]) = {"tagfile", NULL};
2724#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725#ifdef FEAT_WAK
2726static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2727#endif
2728static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2729#ifdef FEAT_VISUAL
2730static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2731static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2732#endif
2733#ifdef FEAT_VISUAL
2734static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2735#endif
2736#ifdef FEAT_BROWSE
2737static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2738#endif
2739#ifdef FEAT_SCROLLBIND
2740static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2741#endif
2742static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002743static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744#ifdef FEAT_VERTSPLIT
2745static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2746#endif
2747#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002748# ifdef FEAT_AUTOCMD
2749static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2750# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002752# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2754#endif
2755static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2756#ifdef FEAT_FOLDING
2757static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002758# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002760# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 NULL};
2762static char *(p_fcl_values[]) = {"all", NULL};
2763#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002764#ifdef FEAT_INS_EXPAND
Bram Moolenaar65c923a2006-03-03 22:56:30 +00002765static char *(p_cot_values[]) = {"menu", "menuone", "longest", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767
2768static void set_option_default __ARGS((int, int opt_flags, int compatible));
2769static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002770static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002771static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772static char_u *illegal_char __ARGS((char_u *, int));
2773static int string_to_key __ARGS((char_u *arg));
2774#ifdef FEAT_CMDWIN
2775static char_u *check_cedit __ARGS((void));
2776#endif
2777#ifdef FEAT_TITLE
2778static void did_set_title __ARGS((int icon));
2779#endif
2780static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2781static void didset_options __ARGS((void));
2782static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002783#if defined(FEAT_EVAL) || defined(PROTO)
2784static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2785#else
2786# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2789static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2790static 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));
2791static char_u *set_chars_option __ARGS((char_u **varp));
2792#ifdef FEAT_CLIPBOARD
2793static char_u *check_clipboard_option __ARGS((void));
2794#endif
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002795#ifdef FEAT_SYN_HL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002796static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002797#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002798#ifdef FEAT_EVAL
2799static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002802static 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 +00002803static void check_redraw __ARGS((long_u flags));
2804static int findoption __ARGS((char_u *));
2805static int find_key_option __ARGS((char_u *));
2806static void showoptions __ARGS((int all, int opt_flags));
2807static int optval_default __ARGS((struct vimoption *, char_u *varp));
2808static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2809static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2810static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2811static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2812static int istermoption __ARGS((struct vimoption *));
2813static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2814static char_u *get_varp __ARGS((struct vimoption *));
2815static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2816static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2817#ifdef FEAT_LANGMAP
2818static void langmap_init __ARGS((void));
2819static void langmap_set __ARGS((void));
2820#endif
2821static void paste_option_changed __ARGS((void));
2822static void compatible_set __ARGS((void));
2823#ifdef FEAT_LINEBREAK
2824static void fill_breakat_flags __ARGS((void));
2825#endif
2826static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2827static int check_opt_strings __ARGS((char_u *val, char **values, int));
2828static int check_opt_wim __ARGS((void));
2829
2830/*
2831 * Initialize the options, first part.
2832 *
2833 * Called only once from main(), just after creating the first buffer.
2834 */
2835 void
2836set_init_1()
2837{
2838 char_u *p;
2839 int opt_idx;
2840 long n;
2841
2842#ifdef FEAT_LANGMAP
2843 langmap_init();
2844#endif
2845
2846 /* Be Vi compatible by default */
2847 p_cp = TRUE;
2848
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002849 /* Use POSIX compatibility when $VIM_POSIX is set. */
2850 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002851 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002852 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002853 set_string_default("shm", (char_u *)"A");
2854 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002855
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 /*
2857 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002858 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002860 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2862# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002863 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002865 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002867 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868# endif
2869#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002870 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 set_string_default("sh", p);
2872
2873#ifdef FEAT_WILDIGN
2874 /*
2875 * Set the default for 'backupskip' to include environment variables for
2876 * temp files.
2877 */
2878 {
2879# ifdef UNIX
2880 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2881# else
2882 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2883# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002884 int len;
2885 garray_T ga;
2886 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887
2888 ga_init2(&ga, 1, 100);
2889 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2890 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002891 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892# ifdef UNIX
2893 if (*names[n] == NUL)
2894 p = (char_u *)"/tmp";
2895 else
2896# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002897 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 if (p != NULL && *p != NUL)
2899 {
2900 /* First time count the NUL, otherwise count the ','. */
2901 len = STRLEN(p) + 3;
2902 if (ga_grow(&ga, len) == OK)
2903 {
2904 if (ga.ga_len > 0)
2905 STRCAT(ga.ga_data, ",");
2906 STRCAT(ga.ga_data, p);
2907 add_pathsep(ga.ga_data);
2908 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 ga.ga_len += len;
2910 }
2911 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002912 if (mustfree)
2913 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 }
2915 if (ga.ga_data != NULL)
2916 {
2917 set_string_default("bsk", ga.ga_data);
2918 vim_free(ga.ga_data);
2919 }
2920 }
2921#endif
2922
2923 /*
2924 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2925 */
2926 opt_idx = findoption((char_u *)"maxmemtot");
2927#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2928 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2929#endif
2930 {
2931#ifdef HAVE_AVAIL_MEM
2932 /* Use amount of memory available at this moment. */
2933 n = (mch_avail_mem(FALSE) >> 11);
2934#else
2935# ifdef HAVE_TOTAL_MEM
2936 /* Use amount of memory available to Vim. */
2937 n = (mch_total_mem(FALSE) >> 11);
2938# else
2939 n = (0x7fffffff >> 11);
2940# endif
2941#endif
2942 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2943 opt_idx = findoption((char_u *)"maxmem");
2944#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2945 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2946 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2947#endif
2948 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2949 }
2950
2951#ifdef FEAT_GUI_W32
2952 /* force 'shortname' for Win32s */
2953 if (gui_is_win32s())
2954 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2955 (char_u *)TRUE;
2956#endif
2957
2958#ifdef FEAT_SEARCHPATH
2959 {
2960 char_u *cdpath;
2961 char_u *buf;
2962 int i;
2963 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002964 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965
2966 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00002967 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 if (cdpath != NULL)
2969 {
2970 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2971 if (buf != NULL)
2972 {
2973 buf[0] = ','; /* start with ",", current dir first */
2974 j = 1;
2975 for (i = 0; cdpath[i] != NUL; ++i)
2976 {
2977 if (vim_ispathlistsep(cdpath[i]))
2978 buf[j++] = ',';
2979 else
2980 {
2981 if (cdpath[i] == ' ' || cdpath[i] == ',')
2982 buf[j++] = '\\';
2983 buf[j++] = cdpath[i];
2984 }
2985 }
2986 buf[j] = NUL;
2987 opt_idx = findoption((char_u *)"cdpath");
2988 options[opt_idx].def_val[VI_DEFAULT] = buf;
2989 options[opt_idx].flags |= P_DEF_ALLOCED;
2990 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002991 if (mustfree)
2992 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 }
2994 }
2995#endif
2996
2997#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2998 /* Set print encoding on platforms that don't default to latin1 */
2999 set_string_default("penc",
3000# if defined(MSWIN) || defined(OS2)
3001 (char_u *)"cp1252"
3002# else
3003# ifdef VMS
3004 (char_u *)"dec-mcs"
3005# else
3006# ifdef EBCDIC
3007 (char_u *)"ebcdic-uk"
3008# else
3009# ifdef MAC
3010 (char_u *)"mac-roman"
3011# else /* HPUX */
3012 (char_u *)"hp-roman8"
3013# endif
3014# endif
3015# endif
3016# endif
3017 );
3018#endif
3019
3020#ifdef FEAT_POSTSCRIPT
3021 /* 'printexpr' must be allocated to be able to evaluate it. */
3022 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003023# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3024 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025# else
3026# ifdef VMS
3027 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3028
3029# else
3030 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3031# endif
3032# endif
3033 );
3034#endif
3035
3036 /*
3037 * Set all the options (except the terminal options) to their default
3038 * value. Also set the global value for local options.
3039 */
3040 set_options_default(0);
3041
3042#ifdef FEAT_GUI
3043 if (found_reverse_arg)
3044 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3045#endif
3046
3047 curbuf->b_p_initialized = TRUE;
3048 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3049 check_buf_options(curbuf);
3050 check_win_options(curwin);
3051 check_options();
3052
3053 /* Must be before option_expand(), because that one needs vim_isIDc() */
3054 didset_options();
3055
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003056#ifdef FEAT_SYN_HL
3057 /* Use the current chartab for the generic chartab. */
3058 init_spell_chartab();
3059#endif
3060
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061#ifdef FEAT_LINEBREAK
3062 /*
3063 * initialize the table for 'breakat'.
3064 */
3065 fill_breakat_flags();
3066#endif
3067
3068 /*
3069 * Expand environment variables and things like "~" for the defaults.
3070 * If option_expand() returns non-NULL the variable is expanded. This can
3071 * only happen for non-indirect options.
3072 * Also set the default to the expanded value, so ":set" does not list
3073 * them.
3074 * Don't set the P_ALLOCED flag, because we don't want to free the
3075 * default.
3076 */
3077 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3078 {
3079 if ((options[opt_idx].flags & P_GETTEXT)
3080 && options[opt_idx].var != NULL)
3081 p = (char_u *)_(*(char **)options[opt_idx].var);
3082 else
3083 p = option_expand(opt_idx, NULL);
3084 if (p != NULL && (p = vim_strsave(p)) != NULL)
3085 {
3086 *(char_u **)options[opt_idx].var = p;
3087 /* VIMEXP
3088 * Defaults for all expanded options are currently the same for Vi
3089 * and Vim. When this changes, add some code here! Also need to
3090 * split P_DEF_ALLOCED in two.
3091 */
3092 if (options[opt_idx].flags & P_DEF_ALLOCED)
3093 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3094 options[opt_idx].def_val[VI_DEFAULT] = p;
3095 options[opt_idx].flags |= P_DEF_ALLOCED;
3096 }
3097 }
3098
3099 /* Initialize the highlight_attr[] table. */
3100 highlight_changed();
3101
3102 save_file_ff(curbuf); /* Buffer is unchanged */
3103
3104 /* Parse default for 'wildmode' */
3105 check_opt_wim();
3106
3107#if defined(FEAT_ARABIC)
3108 /* Detect use of mlterm.
3109 * Mlterm is a terminal emulator akin to xterm that has some special
3110 * abilities (bidi namely).
3111 * NOTE: mlterm's author is being asked to 'set' a variable
3112 * instead of an environment variable due to inheritance.
3113 */
3114 if (mch_getenv((char_u *)"MLTERM") != NULL)
3115 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3116#endif
3117
3118#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3119 /* Parse default for 'fillchars'. */
3120 (void)set_chars_option(&p_fcs);
3121#endif
3122
3123#ifdef FEAT_CLIPBOARD
3124 /* Parse default for 'clipboard' */
3125 (void)check_clipboard_option();
3126#endif
3127
3128#ifdef FEAT_MBYTE
3129# if defined(WIN3264) && defined(FEAT_GETTEXT)
3130 /*
3131 * If $LANG isn't set, try to get a good value for it. This makes the
3132 * right language be used automatically. Don't do this for English.
3133 */
3134 if (mch_getenv((char_u *)"LANG") == NULL)
3135 {
3136 char buf[20];
3137
3138 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3139 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3140 * only the first two. */
3141 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3142 (LPTSTR)buf, 20);
3143 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3144 {
3145 /* There are a few exceptions (probably more) */
3146 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3147 STRCPY(buf, "zh_TW");
3148 else if (STRNICMP(buf, "chs", 3) == 0
3149 || STRNICMP(buf, "zhc", 3) == 0)
3150 STRCPY(buf, "zh_CN");
3151 else if (STRNICMP(buf, "jp", 2) == 0)
3152 STRCPY(buf, "ja");
3153 else
3154 buf[2] = NUL; /* truncate to two-letter code */
3155 vim_setenv("LANG", buf);
3156 }
3157 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003158# else
3159# ifdef MACOS
3160 if (mch_getenv((char_u *)"LANG") == NULL)
3161 {
3162 char buf[20];
3163 if (LocaleRefGetPartString(NULL,
3164 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3165 kLocaleRegionMask | kLocaleRegionVariantMask,
3166 sizeof buf, buf) == noErr && *buf)
3167 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003168 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003169# ifdef HAVE_LOCALE_H
3170 setlocale(LC_ALL, "");
3171# endif
3172 }
3173 }
3174# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175# endif
3176
3177 /* enc_locale() will try to find the encoding of the current locale. */
3178 p = enc_locale();
3179 if (p != NULL)
3180 {
3181 char_u *save_enc;
3182
3183 /* Try setting 'encoding' and check if the value is valid.
3184 * If not, go back to the default "latin1". */
3185 save_enc = p_enc;
3186 p_enc = p;
3187 if (mb_init() == NULL)
3188 {
3189 opt_idx = findoption((char_u *)"encoding");
3190 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3191 options[opt_idx].flags |= P_DEF_ALLOCED;
3192
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003193#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3194 || defined(VMS)
3195 if (STRCMP(p_enc, "latin1") == 0
3196# ifdef FEAT_MBYTE
3197 || enc_utf8
3198# endif
3199 )
3200 {
3201 /* Adjust the default for 'isprint' to match latin1. */
3202 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003203 (char_u *)"@,161-255", OPT_FREE, SID_NONE);
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003204 (void)init_chartab();
3205 }
3206#endif
3207
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208# if defined(WIN3264) && !defined(FEAT_GUI)
3209 /* Win32 console: When GetACP() returns a different value from
3210 * GetConsoleCP() set 'termencoding'. */
3211 if (GetACP() != GetConsoleCP())
3212 {
3213 char buf[50];
3214
3215 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3216 p_tenc = vim_strsave((char_u *)buf);
3217 if (p_tenc != NULL)
3218 {
3219 opt_idx = findoption((char_u *)"termencoding");
3220 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3221 options[opt_idx].flags |= P_DEF_ALLOCED;
3222 convert_setup(&input_conv, p_tenc, p_enc);
3223 convert_setup(&output_conv, p_enc, p_tenc);
3224 }
3225 else
3226 p_tenc = empty_option;
3227 }
3228# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003229# if defined(WIN3264) && defined(FEAT_MBYTE)
3230 /* $HOME may have characters in active code page. */
3231 init_homedir();
3232# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233 }
3234 else
3235 {
3236 vim_free(p_enc);
3237 p_enc = save_enc;
3238 }
3239 }
3240#endif
3241
3242#ifdef FEAT_MULTI_LANG
3243 /* Set the default for 'helplang'. */
3244 set_helplang_default(get_mess_lang());
3245#endif
3246}
3247
3248/*
3249 * Set an option to its default value.
3250 * This does not take care of side effects!
3251 */
3252 static void
3253set_option_default(opt_idx, opt_flags, compatible)
3254 int opt_idx;
3255 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3256 int compatible; /* use Vi default value */
3257{
3258 char_u *varp; /* pointer to variable for current option */
3259 int dvi; /* index in def_val[] */
3260 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003261 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3263
3264 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3265 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003266 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267 {
3268 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3269 if (flags & P_STRING)
3270 {
3271 /* Use set_string_option_direct() for local options to handle
3272 * freeing and allocating the value. */
3273 if (options[opt_idx].indir != PV_NONE)
3274 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003275 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 else
3277 {
3278 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3279 free_string_option(*(char_u **)(varp));
3280 *(char_u **)varp = options[opt_idx].def_val[dvi];
3281 options[opt_idx].flags &= ~P_ALLOCED;
3282 }
3283 }
3284 else if (flags & P_NUM)
3285 {
3286 if (varp == (char_u *)PV_SCROLL)
3287 win_comp_scroll(curwin);
3288 else
3289 {
3290 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3291 /* May also set global value for local option. */
3292 if (both)
3293 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3294 *(long *)varp;
3295 }
3296 }
3297 else /* P_BOOL */
3298 {
3299 /* the cast to long is required for Manx C */
3300 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3301 /* May also set global value for local option. */
3302 if (both)
3303 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3304 *(int *)varp;
3305 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003306
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003307 /* The default value is not insecure. */
3308 flagsp = insecure_flag(opt_idx, opt_flags);
3309 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 }
3311
3312#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003313 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314#endif
3315}
3316
3317/*
3318 * Set all options (except terminal options) to their default value.
3319 */
3320 static void
3321set_options_default(opt_flags)
3322 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3323{
3324 int i;
3325#ifdef FEAT_WINDOWS
3326 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003327 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#endif
3329
3330 for (i = 0; !istermoption(&options[i]); i++)
3331 if (!(options[i].flags & P_NODEFAULT))
3332 set_option_default(i, opt_flags, p_cp);
3333
3334#ifdef FEAT_WINDOWS
3335 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003336 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 win_comp_scroll(wp);
3338#else
3339 win_comp_scroll(curwin);
3340#endif
3341}
3342
3343/*
3344 * Set the Vi-default value of a string option.
3345 * Used for 'sh', 'backupskip' and 'term'.
3346 */
3347 void
3348set_string_default(name, val)
3349 char *name;
3350 char_u *val;
3351{
3352 char_u *p;
3353 int opt_idx;
3354
3355 p = vim_strsave(val);
3356 if (p != NULL) /* we don't want a NULL */
3357 {
3358 opt_idx = findoption((char_u *)name);
3359 if (options[opt_idx].flags & P_DEF_ALLOCED)
3360 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3361 options[opt_idx].def_val[VI_DEFAULT] = p;
3362 options[opt_idx].flags |= P_DEF_ALLOCED;
3363 }
3364}
3365
3366/*
3367 * Set the Vi-default value of a number option.
3368 * Used for 'lines' and 'columns'.
3369 */
3370 void
3371set_number_default(name, val)
3372 char *name;
3373 long val;
3374{
3375 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3376}
3377
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003378#if defined(EXITFREE) || defined(PROTO)
3379/*
3380 * Free all options.
3381 */
3382 void
3383free_all_options()
3384{
3385 int i;
3386
3387 for (i = 0; !istermoption(&options[i]); i++)
3388 {
3389 if (options[i].indir == PV_NONE)
3390 {
3391 /* global option: free value and default value. */
3392 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3393 free_string_option(*(char_u **)options[i].var);
3394 if (options[i].flags & P_DEF_ALLOCED)
3395 free_string_option(options[i].def_val[VI_DEFAULT]);
3396 }
3397 else if (options[i].var != VAR_WIN
3398 && (options[i].flags & P_STRING))
3399 /* buffer-local option: free global value */
3400 free_string_option(*(char_u **)options[i].var);
3401 }
3402}
3403#endif
3404
3405
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406/*
3407 * Initialize the options, part two: After getting Rows and Columns and
3408 * setting 'term'.
3409 */
3410 void
3411set_init_2()
3412{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003413 int idx;
3414
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415 /*
3416 * 'scroll' defaults to half the window height. Note that this default is
3417 * wrong when the window height changes.
3418 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003419 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003420 idx = findoption((char_u *)"scroll");
3421 if (!(options[idx].flags & P_WAS_SET))
3422 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 comp_col();
3424
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003425 /*
3426 * 'window' is only for backwards compatibility with Vi.
3427 * Default is Rows - 1.
3428 */
3429 idx = findoption((char_u *)"wi");
3430 if (!(options[idx].flags & P_WAS_SET))
3431 p_window = Rows - 1;
3432 set_number_default("window", Rows - 1);
3433
Bram Moolenaarf740b292006-02-16 22:11:02 +00003434 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003436 /*
3437 * If 'background' wasn't set by the user, try guessing the value,
3438 * depending on the terminal name. Only need to check for terminals
3439 * with a dark background, that can handle color.
3440 */
3441 idx = findoption((char_u *)"bg");
3442 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003444 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003445 /* don't mark it as set, when starting the GUI it may be
3446 * changed again */
3447 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 }
3449#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003450
3451#ifdef CURSOR_SHAPE
3452 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3453#endif
3454#ifdef FEAT_MOUSESHAPE
3455 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3456#endif
3457#ifdef FEAT_PRINTER
3458 (void)parse_printoptions(); /* parse 'printoptions' default value */
3459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460}
3461
3462/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003463 * Return "dark" or "light" depending on the kind of terminal.
3464 * This is just guessing! Recognized are:
3465 * "linux" Linux console
3466 * "screen.linux" Linux console with screen
3467 * "cygwin" Cygwin shell
3468 * "putty" Putty program
3469 * We also check the COLORFGBG environment variable, which is set by
3470 * rxvt and derivatives. This variable contains either two or three
3471 * values separated by semicolons; we want the last value in either
3472 * case. If this value is 0-6 or 8, our background is dark.
3473 */
3474 static char_u *
3475term_bg_default()
3476{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003477#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3478 /* DOS console nearly always black */
3479 return (char_u *)"dark";
3480#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003481 char_u *p;
3482
Bram Moolenaarf740b292006-02-16 22:11:02 +00003483 if (STRCMP(T_NAME, "linux") == 0
3484 || STRCMP(T_NAME, "screen.linux") == 0
3485 || STRCMP(T_NAME, "cygwin") == 0
3486 || STRCMP(T_NAME, "putty") == 0
3487 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3488 && (p = vim_strrchr(p, ';')) != NULL
3489 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3490 && p[2] == NUL))
3491 return (char_u *)"dark";
3492 return (char_u *)"light";
3493#endif
3494}
3495
3496/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 * Initialize the options, part three: After reading the .vimrc
3498 */
3499 void
3500set_init_3()
3501{
3502#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3503/*
3504 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3505 * This is done after other initializations, where 'shell' might have been
3506 * set, but only if they have not been set before.
3507 */
3508 char_u *p;
3509 int idx_srr;
3510 int do_srr;
3511#ifdef FEAT_QUICKFIX
3512 int idx_sp;
3513 int do_sp;
3514#endif
3515
3516 idx_srr = findoption((char_u *)"srr");
3517 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3518#ifdef FEAT_QUICKFIX
3519 idx_sp = findoption((char_u *)"sp");
3520 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3521#endif
3522
3523 /*
3524 * Isolate the name of the shell:
3525 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3526 * - Remove any argument. E.g., "csh -f" -> "csh".
3527 */
3528 p = gettail(p_sh);
3529 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3530 if (p != NULL)
3531 {
3532 /*
3533 * Default for p_sp is "| tee", for p_srr is ">".
3534 * For known shells it is changed here to include stderr.
3535 */
3536 if ( fnamecmp(p, "csh") == 0
3537 || fnamecmp(p, "tcsh") == 0
3538# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3539 || fnamecmp(p, "csh.exe") == 0
3540 || fnamecmp(p, "tcsh.exe") == 0
3541# endif
3542 )
3543 {
3544#if defined(FEAT_QUICKFIX)
3545 if (do_sp)
3546 {
3547# ifdef WIN3264
3548 p_sp = (char_u *)">&";
3549# else
3550 p_sp = (char_u *)"|& tee";
3551# endif
3552 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3553 }
3554#endif
3555 if (do_srr)
3556 {
3557 p_srr = (char_u *)">&";
3558 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3559 }
3560 }
3561 else
3562# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3563 if ( fnamecmp(p, "sh") == 0
3564 || fnamecmp(p, "ksh") == 0
3565 || fnamecmp(p, "zsh") == 0
3566 || fnamecmp(p, "bash") == 0
3567# ifdef WIN3264
3568 || fnamecmp(p, "cmd") == 0
3569 || fnamecmp(p, "sh.exe") == 0
3570 || fnamecmp(p, "ksh.exe") == 0
3571 || fnamecmp(p, "zsh.exe") == 0
3572 || fnamecmp(p, "bash.exe") == 0
3573 || fnamecmp(p, "cmd.exe") == 0
3574# endif
3575 )
3576# endif
3577 {
3578#if defined(FEAT_QUICKFIX)
3579 if (do_sp)
3580 {
3581# ifdef WIN3264
3582 p_sp = (char_u *)">%s 2>&1";
3583# else
3584 p_sp = (char_u *)"2>&1| tee";
3585# endif
3586 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3587 }
3588#endif
3589 if (do_srr)
3590 {
3591 p_srr = (char_u *)">%s 2>&1";
3592 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3593 }
3594 }
3595 vim_free(p);
3596 }
3597#endif
3598
3599#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3600 /*
3601 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3602 * This is done after other initializations, where 'shell' might have been
3603 * set, but only if they have not been set before. Default for p_shcf is
3604 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3605 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3606 * command.com. And for Win32 we need to set p_sxq instead.
3607 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003608 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 {
3610 int idx3;
3611
3612 idx3 = findoption((char_u *)"shcf");
3613 if (!(options[idx3].flags & P_WAS_SET))
3614 {
3615 p_shcf = (char_u *)"-c";
3616 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3617 }
3618
3619# ifndef DJGPP
3620# ifdef WIN3264
3621 /* Somehow Win32 requires the quotes around the redirection too */
3622 idx3 = findoption((char_u *)"sxq");
3623 if (!(options[idx3].flags & P_WAS_SET))
3624 {
3625 p_sxq = (char_u *)"\"";
3626 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3627 }
3628# else
3629 idx3 = findoption((char_u *)"shq");
3630 if (!(options[idx3].flags & P_WAS_SET))
3631 {
3632 p_shq = (char_u *)"\"";
3633 options[idx3].def_val[VI_DEFAULT] = p_shq;
3634 }
3635# endif
3636# endif
3637 }
3638#endif
3639
3640#ifdef FEAT_TITLE
3641 set_title_defaults();
3642#endif
3643}
3644
3645#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3646/*
3647 * When 'helplang' is still at its default value, set it to "lang".
3648 * Only the first two characters of "lang" are used.
3649 */
3650 void
3651set_helplang_default(lang)
3652 char_u *lang;
3653{
3654 int idx;
3655
3656 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3657 return;
3658 idx = findoption((char_u *)"hlg");
3659 if (!(options[idx].flags & P_WAS_SET))
3660 {
3661 if (options[idx].flags & P_ALLOCED)
3662 free_string_option(p_hlg);
3663 p_hlg = vim_strsave(lang);
3664 if (p_hlg == NULL)
3665 p_hlg = empty_option;
3666 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003667 {
3668 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3669 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3670 {
3671 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3672 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 options[idx].flags |= P_ALLOCED;
3677 }
3678}
3679#endif
3680
3681#ifdef FEAT_GUI
3682static char_u *gui_bg_default __ARGS((void));
3683
3684 static char_u *
3685gui_bg_default()
3686{
3687 if (gui_get_lightness(gui.back_pixel) < 127)
3688 return (char_u *)"dark";
3689 return (char_u *)"light";
3690}
3691
3692/*
3693 * Option initializations that can only be done after opening the GUI window.
3694 */
3695 void
3696init_gui_options()
3697{
3698 /* Set the 'background' option according to the lightness of the
3699 * background color, unless the user has set it already. */
3700 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3701 {
3702 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3703 highlight_changed();
3704 }
3705}
3706#endif
3707
3708#ifdef FEAT_TITLE
3709/*
3710 * 'title' and 'icon' only default to true if they have not been set or reset
3711 * in .vimrc and we can read the old value.
3712 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3713 * they can be reset. This reduces startup time when using X on a remote
3714 * machine.
3715 */
3716 void
3717set_title_defaults()
3718{
3719 int idx1;
3720 long val;
3721
3722 /*
3723 * If GUI is (going to be) used, we can always set the window title and
3724 * icon name. Saves a bit of time, because the X11 display server does
3725 * not need to be contacted.
3726 */
3727 idx1 = findoption((char_u *)"title");
3728 if (!(options[idx1].flags & P_WAS_SET))
3729 {
3730#ifdef FEAT_GUI
3731 if (gui.starting || gui.in_use)
3732 val = TRUE;
3733 else
3734#endif
3735 val = mch_can_restore_title();
3736 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3737 p_title = val;
3738 }
3739 idx1 = findoption((char_u *)"icon");
3740 if (!(options[idx1].flags & P_WAS_SET))
3741 {
3742#ifdef FEAT_GUI
3743 if (gui.starting || gui.in_use)
3744 val = TRUE;
3745 else
3746#endif
3747 val = mch_can_restore_icon();
3748 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3749 p_icon = val;
3750 }
3751}
3752#endif
3753
3754/*
3755 * Parse 'arg' for option settings.
3756 *
3757 * 'arg' may be IObuff, but only when no errors can be present and option
3758 * does not need to be expanded with option_expand().
3759 * "opt_flags":
3760 * 0 for ":set"
3761 * OPT_GLOBAL for ":setglobal"
3762 * OPT_LOCAL for ":setlocal" and a modeline
3763 * OPT_MODELINE for a modeline
3764 *
3765 * returns FAIL if an error is detected, OK otherwise
3766 */
3767 int
3768do_set(arg, opt_flags)
3769 char_u *arg; /* option string (may be written to!) */
3770 int opt_flags;
3771{
3772 int opt_idx;
3773 char_u *errmsg;
3774 char_u errbuf[80];
3775 char_u *startarg;
3776 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3777 int nextchar; /* next non-white char after option name */
3778 int afterchar; /* character just after option name */
3779 int len;
3780 int i;
3781 long value;
3782 int key;
3783 long_u flags; /* flags for current option */
3784 char_u *varp = NULL; /* pointer to variable for current option */
3785 int did_show = FALSE; /* already showed one value */
3786 int adding; /* "opt+=arg" */
3787 int prepending; /* "opt^=arg" */
3788 int removing; /* "opt-=arg" */
3789 int cp_val = 0;
3790 char_u key_name[2];
3791
3792 if (*arg == NUL)
3793 {
3794 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003795 did_show = TRUE;
3796 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 }
3798
3799 while (*arg != NUL) /* loop to process all options */
3800 {
3801 errmsg = NULL;
3802 startarg = arg; /* remember for error message */
3803
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003804 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3805 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 {
3807 /*
3808 * ":set all" show all options.
3809 * ":set all&" set all options to their default value.
3810 */
3811 arg += 3;
3812 if (*arg == '&')
3813 {
3814 ++arg;
3815 /* Only for :set command set global value of local options. */
3816 set_options_default(OPT_FREE | opt_flags);
3817 }
3818 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003819 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003821 did_show = TRUE;
3822 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003824 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 {
3826 showoptions(2, opt_flags);
3827 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003828 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 arg += 7;
3830 }
3831 else
3832 {
3833 prefix = 1;
3834 if (STRNCMP(arg, "no", 2) == 0)
3835 {
3836 prefix = 0;
3837 arg += 2;
3838 }
3839 else if (STRNCMP(arg, "inv", 3) == 0)
3840 {
3841 prefix = 2;
3842 arg += 3;
3843 }
3844
3845 /* find end of name */
3846 key = 0;
3847 if (*arg == '<')
3848 {
3849 nextchar = 0;
3850 opt_idx = -1;
3851 /* look out for <t_>;> */
3852 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3853 len = 5;
3854 else
3855 {
3856 len = 1;
3857 while (arg[len] != NUL && arg[len] != '>')
3858 ++len;
3859 }
3860 if (arg[len] != '>')
3861 {
3862 errmsg = e_invarg;
3863 goto skip;
3864 }
3865 arg[len] = NUL; /* put NUL after name */
3866 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3867 opt_idx = findoption(arg + 1);
3868 arg[len++] = '>'; /* restore '>' */
3869 if (opt_idx == -1)
3870 key = find_key_option(arg + 1);
3871 }
3872 else
3873 {
3874 len = 0;
3875 /*
3876 * The two characters after "t_" may not be alphanumeric.
3877 */
3878 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3879 len = 4;
3880 else
3881 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3882 ++len;
3883 nextchar = arg[len];
3884 arg[len] = NUL; /* put NUL after name */
3885 opt_idx = findoption(arg);
3886 arg[len] = nextchar; /* restore nextchar */
3887 if (opt_idx == -1)
3888 key = find_key_option(arg);
3889 }
3890
3891 /* remember character after option name */
3892 afterchar = arg[len];
3893
3894 /* skip white space, allow ":set ai ?" */
3895 while (vim_iswhite(arg[len]))
3896 ++len;
3897
3898 adding = FALSE;
3899 prepending = FALSE;
3900 removing = FALSE;
3901 if (arg[len] != NUL && arg[len + 1] == '=')
3902 {
3903 if (arg[len] == '+')
3904 {
3905 adding = TRUE; /* "+=" */
3906 ++len;
3907 }
3908 else if (arg[len] == '^')
3909 {
3910 prepending = TRUE; /* "^=" */
3911 ++len;
3912 }
3913 else if (arg[len] == '-')
3914 {
3915 removing = TRUE; /* "-=" */
3916 ++len;
3917 }
3918 }
3919 nextchar = arg[len];
3920
3921 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3922 {
3923 errmsg = (char_u *)N_("E518: Unknown option");
3924 goto skip;
3925 }
3926
3927 if (opt_idx >= 0)
3928 {
3929 if (options[opt_idx].var == NULL) /* hidden option: skip */
3930 {
3931 /* Only give an error message when requesting the value of
3932 * a hidden option, ignore setting it. */
3933 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3934 && (!(options[opt_idx].flags & P_BOOL)
3935 || nextchar == '?'))
3936 errmsg = (char_u *)N_("E519: Option not supported");
3937 goto skip;
3938 }
3939
3940 flags = options[opt_idx].flags;
3941 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3942 }
3943 else
3944 {
3945 flags = P_STRING;
3946 if (key < 0)
3947 {
3948 key_name[0] = KEY2TERMCAP0(key);
3949 key_name[1] = KEY2TERMCAP1(key);
3950 }
3951 else
3952 {
3953 key_name[0] = KS_KEY;
3954 key_name[1] = (key & 0xff);
3955 }
3956 }
3957
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003958 /* Skip all options that are not window-local (used when showing
3959 * an already loaded buffer in a window). */
3960 if ((opt_flags & OPT_WINONLY)
3961 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3962 goto skip;
3963
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 /* Disallow changing some options from modelines */
3965 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3966 {
3967 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3968 goto skip;
3969 }
3970
3971#ifdef HAVE_SANDBOX
3972 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003973 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 {
3975 errmsg = (char_u *)_(e_sandbox);
3976 goto skip;
3977 }
3978#endif
3979
3980 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3981 {
3982 arg += len;
3983 cp_val = p_cp;
3984 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3985 {
3986 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3987 {
3988 cp_val = FALSE;
3989 arg += 3;
3990 }
3991 else /* "opt&vi": set to Vi default */
3992 {
3993 cp_val = TRUE;
3994 arg += 2;
3995 }
3996 }
3997 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3998 && arg[1] != NUL && !vim_iswhite(arg[1]))
3999 {
4000 errmsg = e_trailing;
4001 goto skip;
4002 }
4003 }
4004
4005 /*
4006 * allow '=' and ':' as MSDOS command.com allows only one
4007 * '=' character per "set" command line. grrr. (jw)
4008 */
4009 if (nextchar == '?'
4010 || (prefix == 1
4011 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4012 && !(flags & P_BOOL)))
4013 {
4014 /*
4015 * print value
4016 */
4017 if (did_show)
4018 msg_putchar('\n'); /* cursor below last one */
4019 else
4020 {
4021 gotocmdline(TRUE); /* cursor at status line */
4022 did_show = TRUE; /* remember that we did a line */
4023 }
4024 if (opt_idx >= 0)
4025 {
4026 showoneopt(&options[opt_idx], opt_flags);
4027#ifdef FEAT_EVAL
4028 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004029 {
4030 /* Mention where the option was last set. */
4031 if (varp == options[opt_idx].var)
4032 last_set_msg(options[opt_idx].scriptID);
4033 else if ((int)options[opt_idx].indir & PV_WIN)
4034 last_set_msg(curwin->w_p_scriptID[
4035 (int)options[opt_idx].indir & PV_MASK]);
4036 else if ((int)options[opt_idx].indir & PV_BUF)
4037 last_set_msg(curbuf->b_p_scriptID[
4038 (int)options[opt_idx].indir & PV_MASK]);
4039 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040#endif
4041 }
4042 else
4043 {
4044 char_u *p;
4045
4046 p = find_termcode(key_name);
4047 if (p == NULL)
4048 {
4049 errmsg = (char_u *)N_("E518: Unknown option");
4050 goto skip;
4051 }
4052 else
4053 (void)show_one_termcode(key_name, p, TRUE);
4054 }
4055 if (nextchar != '?'
4056 && nextchar != NUL && !vim_iswhite(afterchar))
4057 errmsg = e_trailing;
4058 }
4059 else
4060 {
4061 if (flags & P_BOOL) /* boolean */
4062 {
4063 if (nextchar == '=' || nextchar == ':')
4064 {
4065 errmsg = e_invarg;
4066 goto skip;
4067 }
4068
4069 /*
4070 * ":set opt!": invert
4071 * ":set opt&": reset to default value
4072 * ":set opt<": reset to global value
4073 */
4074 if (nextchar == '!')
4075 value = *(int *)(varp) ^ 1;
4076 else if (nextchar == '&')
4077 value = (int)(long)options[opt_idx].def_val[
4078 ((flags & P_VI_DEF) || cp_val)
4079 ? VI_DEFAULT : VIM_DEFAULT];
4080 else if (nextchar == '<')
4081 {
4082 /* For 'autoread' -1 means to use global value. */
4083 if ((int *)varp == &curbuf->b_p_ar
4084 && opt_flags == OPT_LOCAL)
4085 value = -1;
4086 else
4087 value = *(int *)get_varp_scope(&(options[opt_idx]),
4088 OPT_GLOBAL);
4089 }
4090 else
4091 {
4092 /*
4093 * ":set invopt": invert
4094 * ":set opt" or ":set noopt": set or reset
4095 */
4096 if (nextchar != NUL && !vim_iswhite(afterchar))
4097 {
4098 errmsg = e_trailing;
4099 goto skip;
4100 }
4101 if (prefix == 2) /* inv */
4102 value = *(int *)(varp) ^ 1;
4103 else
4104 value = prefix;
4105 }
4106
4107 errmsg = set_bool_option(opt_idx, varp, (int)value,
4108 opt_flags);
4109 }
4110 else /* numeric or string */
4111 {
4112 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4113 || prefix != 1)
4114 {
4115 errmsg = e_invarg;
4116 goto skip;
4117 }
4118
4119 if (flags & P_NUM) /* numeric */
4120 {
4121 /*
4122 * Different ways to set a number option:
4123 * & set to default value
4124 * < set to global value
4125 * <xx> accept special key codes for 'wildchar'
4126 * c accept any non-digit for 'wildchar'
4127 * [-]0-9 set number
4128 * other error
4129 */
4130 ++arg;
4131 if (nextchar == '&')
4132 value = (long)options[opt_idx].def_val[
4133 ((flags & P_VI_DEF) || cp_val)
4134 ? VI_DEFAULT : VIM_DEFAULT];
4135 else if (nextchar == '<')
4136 value = *(long *)get_varp_scope(&(options[opt_idx]),
4137 OPT_GLOBAL);
4138 else if (((long *)varp == &p_wc
4139 || (long *)varp == &p_wcm)
4140 && (*arg == '<'
4141 || *arg == '^'
4142 || ((!arg[1] || vim_iswhite(arg[1]))
4143 && !VIM_ISDIGIT(*arg))))
4144 {
4145 value = string_to_key(arg);
4146 if (value == 0 && (long *)varp != &p_wcm)
4147 {
4148 errmsg = e_invarg;
4149 goto skip;
4150 }
4151 }
4152 /* allow negative numbers (for 'undolevels') */
4153 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4154 {
4155 i = 0;
4156 if (*arg == '-')
4157 i = 1;
4158#ifdef HAVE_STRTOL
4159 value = strtol((char *)arg, NULL, 0);
4160 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4161 i += 2;
4162#else
4163 value = atol((char *)arg);
4164#endif
4165 while (VIM_ISDIGIT(arg[i]))
4166 ++i;
4167 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4168 {
4169 errmsg = e_invarg;
4170 goto skip;
4171 }
4172 }
4173 else
4174 {
4175 errmsg = (char_u *)N_("E521: Number required after =");
4176 goto skip;
4177 }
4178
4179 if (adding)
4180 value = *(long *)varp + value;
4181 if (prepending)
4182 value = *(long *)varp * value;
4183 if (removing)
4184 value = *(long *)varp - value;
4185 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004186 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 }
4188 else if (opt_idx >= 0) /* string */
4189 {
4190 char_u *save_arg = NULL;
4191 char_u *s = NULL;
4192 char_u *oldval; /* previous value if *varp */
4193 char_u *newval;
4194 char_u *origval;
4195 unsigned newlen;
4196 int comma;
4197 int bs;
4198 int new_value_alloced; /* new string option
4199 was allocated */
4200
4201 /* When using ":set opt=val" for a global option
4202 * with a local value the local value will be
4203 * reset, use the global value here. */
4204 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004205 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 varp = options[opt_idx].var;
4207
4208 /* The old value is kept until we are sure that the
4209 * new value is valid. */
4210 oldval = *(char_u **)varp;
4211 if (nextchar == '&') /* set to default val */
4212 {
4213 newval = options[opt_idx].def_val[
4214 ((flags & P_VI_DEF) || cp_val)
4215 ? VI_DEFAULT : VIM_DEFAULT];
4216 if ((char_u **)varp == &p_bg)
4217 {
4218 /* guess the value of 'background' */
4219#ifdef FEAT_GUI
4220 if (gui.in_use)
4221 newval = gui_bg_default();
4222 else
4223#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004224 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 }
4226
4227 /* expand environment variables and ~ (since the
4228 * default value was already expanded, only
4229 * required when an environment variable was set
4230 * later */
4231 if (newval == NULL)
4232 newval = empty_option;
4233 else
4234 {
4235 s = option_expand(opt_idx, newval);
4236 if (s == NULL)
4237 s = newval;
4238 newval = vim_strsave(s);
4239 }
4240 new_value_alloced = TRUE;
4241 }
4242 else if (nextchar == '<') /* set to global val */
4243 {
4244 newval = vim_strsave(*(char_u **)get_varp_scope(
4245 &(options[opt_idx]), OPT_GLOBAL));
4246 new_value_alloced = TRUE;
4247 }
4248 else
4249 {
4250 ++arg; /* jump to after the '=' or ':' */
4251
4252 /*
4253 * Set 'keywordprg' to ":help" if an empty
4254 * value was passed to :set by the user.
4255 * Misuse errbuf[] for the resulting string.
4256 */
4257 if (varp == (char_u *)&p_kp
4258 && (*arg == NUL || *arg == ' '))
4259 {
4260 STRCPY(errbuf, ":help");
4261 save_arg = arg;
4262 arg = errbuf;
4263 }
4264 /*
4265 * Convert 'whichwrap' number to string, for
4266 * backwards compatibility with Vim 3.0.
4267 * Misuse errbuf[] for the resulting string.
4268 */
4269 else if (varp == (char_u *)&p_ww
4270 && VIM_ISDIGIT(*arg))
4271 {
4272 *errbuf = NUL;
4273 i = getdigits(&arg);
4274 if (i & 1)
4275 STRCAT(errbuf, "b,");
4276 if (i & 2)
4277 STRCAT(errbuf, "s,");
4278 if (i & 4)
4279 STRCAT(errbuf, "h,l,");
4280 if (i & 8)
4281 STRCAT(errbuf, "<,>,");
4282 if (i & 16)
4283 STRCAT(errbuf, "[,],");
4284 if (*errbuf != NUL) /* remove trailing , */
4285 errbuf[STRLEN(errbuf) - 1] = NUL;
4286 save_arg = arg;
4287 arg = errbuf;
4288 }
4289 /*
4290 * Remove '>' before 'dir' and 'bdir', for
4291 * backwards compatibility with version 3.0
4292 */
4293 else if ( *arg == '>'
4294 && (varp == (char_u *)&p_dir
4295 || varp == (char_u *)&p_bdir))
4296 {
4297 ++arg;
4298 }
4299
4300 /* When setting the local value of a global
4301 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004302 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 && (opt_flags & OPT_LOCAL))
4304 origval = *(char_u **)get_varp(
4305 &options[opt_idx]);
4306 else
4307 origval = oldval;
4308
4309 /*
4310 * Copy the new string into allocated memory.
4311 * Can't use set_string_option_direct(), because
4312 * we need to remove the backslashes.
4313 */
4314 /* get a bit too much */
4315 newlen = (unsigned)STRLEN(arg) + 1;
4316 if (adding || prepending || removing)
4317 newlen += (unsigned)STRLEN(origval) + 1;
4318 newval = alloc(newlen);
4319 if (newval == NULL) /* out of mem, don't change */
4320 break;
4321 s = newval;
4322
4323 /*
4324 * Copy the string, skip over escaped chars.
4325 * For MS-DOS and WIN32 backslashes before normal
4326 * file name characters are not removed, and keep
4327 * backslash at start, for "\\machine\path", but
4328 * do remove it for "\\\\machine\\path".
4329 * The reverse is found in ExpandOldSetting().
4330 */
4331 while (*arg && !vim_iswhite(*arg))
4332 {
4333 if (*arg == '\\' && arg[1] != NUL
4334#ifdef BACKSLASH_IN_FILENAME
4335 && !((flags & P_EXPAND)
4336 && vim_isfilec(arg[1])
4337 && (arg[1] != '\\'
4338 || (s == newval
4339 && arg[2] != '\\')))
4340#endif
4341 )
4342 ++arg; /* remove backslash */
4343#ifdef FEAT_MBYTE
4344 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004345 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 {
4347 /* copy multibyte char */
4348 mch_memmove(s, arg, (size_t)i);
4349 arg += i;
4350 s += i;
4351 }
4352 else
4353#endif
4354 *s++ = *arg++;
4355 }
4356 *s = NUL;
4357
4358 /*
4359 * Expand environment variables and ~.
4360 * Don't do it when adding without inserting a
4361 * comma.
4362 */
4363 if (!(adding || prepending || removing)
4364 || (flags & P_COMMA))
4365 {
4366 s = option_expand(opt_idx, newval);
4367 if (s != NULL)
4368 {
4369 vim_free(newval);
4370 newlen = (unsigned)STRLEN(s) + 1;
4371 if (adding || prepending || removing)
4372 newlen += (unsigned)STRLEN(origval) + 1;
4373 newval = alloc(newlen);
4374 if (newval == NULL)
4375 break;
4376 STRCPY(newval, s);
4377 }
4378 }
4379
4380 /* locate newval[] in origval[] when removing it
4381 * and when adding to avoid duplicates */
4382 i = 0; /* init for GCC */
4383 if (removing || (flags & P_NODUP))
4384 {
4385 i = (int)STRLEN(newval);
4386 bs = 0;
4387 for (s = origval; *s; ++s)
4388 {
4389 if ((!(flags & P_COMMA)
4390 || s == origval
4391 || (s[-1] == ',' && !(bs & 1)))
4392 && STRNCMP(s, newval, i) == 0
4393 && (!(flags & P_COMMA)
4394 || s[i] == ','
4395 || s[i] == NUL))
4396 break;
4397 /* Count backspaces. Only a comma with an
4398 * even number of backspaces before it is
4399 * recognized as a separator */
4400 if (s > origval && s[-1] == '\\')
4401 ++bs;
4402 else
4403 bs = 0;
4404 }
4405
4406 /* do not add if already there */
4407 if ((adding || prepending) && *s)
4408 {
4409 prepending = FALSE;
4410 adding = FALSE;
4411 STRCPY(newval, origval);
4412 }
4413 }
4414
4415 /* concatenate the two strings; add a ',' if
4416 * needed */
4417 if (adding || prepending)
4418 {
4419 comma = ((flags & P_COMMA) && *origval != NUL
4420 && *newval != NUL);
4421 if (adding)
4422 {
4423 i = (int)STRLEN(origval);
4424 mch_memmove(newval + i + comma, newval,
4425 STRLEN(newval) + 1);
4426 mch_memmove(newval, origval, (size_t)i);
4427 }
4428 else
4429 {
4430 i = (int)STRLEN(newval);
4431 mch_memmove(newval + i + comma, origval,
4432 STRLEN(origval) + 1);
4433 }
4434 if (comma)
4435 newval[i] = ',';
4436 }
4437
4438 /* Remove newval[] from origval[]. (Note: "i" has
4439 * been set above and is used here). */
4440 if (removing)
4441 {
4442 STRCPY(newval, origval);
4443 if (*s)
4444 {
4445 /* may need to remove a comma */
4446 if (flags & P_COMMA)
4447 {
4448 if (s == origval)
4449 {
4450 /* include comma after string */
4451 if (s[i] == ',')
4452 ++i;
4453 }
4454 else
4455 {
4456 /* include comma before string */
4457 --s;
4458 ++i;
4459 }
4460 }
4461 mch_memmove(newval + (s - origval), s + i,
4462 STRLEN(s + i) + 1);
4463 }
4464 }
4465
4466 if (flags & P_FLAGLIST)
4467 {
4468 /* Remove flags that appear twice. */
4469 for (s = newval; *s; ++s)
4470 if ((!(flags & P_COMMA) || *s != ',')
4471 && vim_strchr(s + 1, *s) != NULL)
4472 {
4473 STRCPY(s, s + 1);
4474 --s;
4475 }
4476 }
4477
4478 if (save_arg != NULL) /* number for 'whichwrap' */
4479 arg = save_arg;
4480 new_value_alloced = TRUE;
4481 }
4482
4483 /* Set the new value. */
4484 *(char_u **)(varp) = newval;
4485
4486 /* Handle side effects, and set the global value for
4487 * ":set" on local options. */
4488 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4489 new_value_alloced, oldval, errbuf, opt_flags);
4490
4491 /* If error detected, print the error message. */
4492 if (errmsg != NULL)
4493 goto skip;
4494 }
4495 else /* key code option */
4496 {
4497 char_u *p;
4498
4499 if (nextchar == '&')
4500 {
4501 if (add_termcap_entry(key_name, TRUE) == FAIL)
4502 errmsg = (char_u *)N_("E522: Not found in termcap");
4503 }
4504 else
4505 {
4506 ++arg; /* jump to after the '=' or ':' */
4507 for (p = arg; *p && !vim_iswhite(*p); ++p)
4508 if (*p == '\\' && p[1] != NUL)
4509 ++p;
4510 nextchar = *p;
4511 *p = NUL;
4512 add_termcode(key_name, arg, FALSE);
4513 *p = nextchar;
4514 }
4515 if (full_screen)
4516 ttest(FALSE);
4517 redraw_all_later(CLEAR);
4518 }
4519 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004520
Bram Moolenaar071d4272004-06-13 20:20:40 +00004521 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004522 did_set_option(opt_idx, opt_flags,
4523 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004524 }
4525
4526skip:
4527 /*
4528 * Advance to next argument.
4529 * - skip until a blank found, taking care of backslashes
4530 * - skip blanks
4531 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4532 */
4533 for (i = 0; i < 2 ; ++i)
4534 {
4535 while (*arg != NUL && !vim_iswhite(*arg))
4536 if (*arg++ == '\\' && *arg != NUL)
4537 ++arg;
4538 arg = skipwhite(arg);
4539 if (*arg != '=')
4540 break;
4541 }
4542 }
4543
4544 if (errmsg != NULL)
4545 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004546 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004547 i = STRLEN(IObuff) + 2;
4548 if (i + (arg - startarg) < IOSIZE)
4549 {
4550 /* append the argument with the error */
4551 STRCAT(IObuff, ": ");
4552 mch_memmove(IObuff + i, startarg, (arg - startarg));
4553 IObuff[i + (arg - startarg)] = NUL;
4554 }
4555 /* make sure all characters are printable */
4556 trans_characters(IObuff, IOSIZE);
4557
4558 ++no_wait_return; /* wait_return done later */
4559 emsg(IObuff); /* show error highlighted */
4560 --no_wait_return;
4561
4562 return FAIL;
4563 }
4564
4565 arg = skipwhite(arg);
4566 }
4567
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004568theend:
4569 if (silent_mode && did_show)
4570 {
4571 /* After displaying option values in silent mode. */
4572 silent_mode = FALSE;
4573 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4574 msg_putchar('\n');
4575 cursor_on(); /* msg_start() switches it off */
4576 out_flush();
4577 silent_mode = TRUE;
4578 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4579 }
4580
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 return OK;
4582}
4583
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004584/*
4585 * Call this when an option has been given a new value through a user command.
4586 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4587 */
4588 static void
4589did_set_option(opt_idx, opt_flags, new_value)
4590 int opt_idx;
4591 int opt_flags; /* possibly with OPT_MODELINE */
4592 int new_value; /* value was replaced completely */
4593{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004594 long_u *p;
4595
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004596 options[opt_idx].flags |= P_WAS_SET;
4597
4598 /* When an option is set in the sandbox, from a modeline or in secure mode
4599 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004600 * flag. */
4601 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004602 if (secure
4603#ifdef HAVE_SANDBOX
4604 || sandbox != 0
4605#endif
4606 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004607 *p = *p | P_INSECURE;
4608 else if (new_value)
4609 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004610}
4611
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 static char_u *
4613illegal_char(errbuf, c)
4614 char_u *errbuf;
4615 int c;
4616{
4617 if (errbuf == NULL)
4618 return (char_u *)"";
4619 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004620 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004621 return errbuf;
4622}
4623
4624/*
4625 * Convert a key name or string into a key value.
4626 * Used for 'wildchar' and 'cedit' options.
4627 */
4628 static int
4629string_to_key(arg)
4630 char_u *arg;
4631{
4632 if (*arg == '<')
4633 return find_key_option(arg + 1);
4634 if (*arg == '^')
4635 return Ctrl_chr(arg[1]);
4636 return *arg;
4637}
4638
4639#ifdef FEAT_CMDWIN
4640/*
4641 * Check value of 'cedit' and set cedit_key.
4642 * Returns NULL if value is OK, error message otherwise.
4643 */
4644 static char_u *
4645check_cedit()
4646{
4647 int n;
4648
4649 if (*p_cedit == NUL)
4650 cedit_key = -1;
4651 else
4652 {
4653 n = string_to_key(p_cedit);
4654 if (vim_isprintc(n))
4655 return e_invarg;
4656 cedit_key = n;
4657 }
4658 return NULL;
4659}
4660#endif
4661
4662#ifdef FEAT_TITLE
4663/*
4664 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4665 * maketitle() to create and display it.
4666 * When switching the title or icon off, call mch_restore_title() to get
4667 * the old value back.
4668 */
4669 static void
4670did_set_title(icon)
4671 int icon; /* Did set icon instead of title */
4672{
4673 if (starting != NO_SCREEN
4674#ifdef FEAT_GUI
4675 && !gui.starting
4676#endif
4677 )
4678 {
4679 maketitle();
4680 if (icon)
4681 {
4682 if (!p_icon)
4683 mch_restore_title(2);
4684 }
4685 else
4686 {
4687 if (!p_title)
4688 mch_restore_title(1);
4689 }
4690 }
4691}
4692#endif
4693
4694/*
4695 * set_options_bin - called when 'bin' changes value.
4696 */
4697 void
4698set_options_bin(oldval, newval, opt_flags)
4699 int oldval;
4700 int newval;
4701 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4702{
4703 /*
4704 * The option values that are changed when 'bin' changes are
4705 * copied when 'bin is set and restored when 'bin' is reset.
4706 */
4707 if (newval)
4708 {
4709 if (!oldval) /* switched on */
4710 {
4711 if (!(opt_flags & OPT_GLOBAL))
4712 {
4713 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4714 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4715 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4716 curbuf->b_p_et_nobin = curbuf->b_p_et;
4717 }
4718 if (!(opt_flags & OPT_LOCAL))
4719 {
4720 p_tw_nobin = p_tw;
4721 p_wm_nobin = p_wm;
4722 p_ml_nobin = p_ml;
4723 p_et_nobin = p_et;
4724 }
4725 }
4726
4727 if (!(opt_flags & OPT_GLOBAL))
4728 {
4729 curbuf->b_p_tw = 0; /* no automatic line wrap */
4730 curbuf->b_p_wm = 0; /* no automatic line wrap */
4731 curbuf->b_p_ml = 0; /* no modelines */
4732 curbuf->b_p_et = 0; /* no expandtab */
4733 }
4734 if (!(opt_flags & OPT_LOCAL))
4735 {
4736 p_tw = 0;
4737 p_wm = 0;
4738 p_ml = FALSE;
4739 p_et = FALSE;
4740 p_bin = TRUE; /* needed when called for the "-b" argument */
4741 }
4742 }
4743 else if (oldval) /* switched off */
4744 {
4745 if (!(opt_flags & OPT_GLOBAL))
4746 {
4747 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4748 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4749 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4750 curbuf->b_p_et = curbuf->b_p_et_nobin;
4751 }
4752 if (!(opt_flags & OPT_LOCAL))
4753 {
4754 p_tw = p_tw_nobin;
4755 p_wm = p_wm_nobin;
4756 p_ml = p_ml_nobin;
4757 p_et = p_et_nobin;
4758 }
4759 }
4760}
4761
4762#ifdef FEAT_VIMINFO
4763/*
4764 * Find the parameter represented by the given character (eg ', :, ", or /),
4765 * and return its associated value in the 'viminfo' string.
4766 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004767 * If the parameter is not specified in the string or there is no following
4768 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 */
4770 int
4771get_viminfo_parameter(type)
4772 int type;
4773{
4774 char_u *p;
4775
4776 p = find_viminfo_parameter(type);
4777 if (p != NULL && VIM_ISDIGIT(*p))
4778 return atoi((char *)p);
4779 return -1;
4780}
4781
4782/*
4783 * Find the parameter represented by the given character (eg ''', ':', '"', or
4784 * '/') in the 'viminfo' option and return a pointer to the string after it.
4785 * Return NULL if the parameter is not specified in the string.
4786 */
4787 char_u *
4788find_viminfo_parameter(type)
4789 int type;
4790{
4791 char_u *p;
4792
4793 for (p = p_viminfo; *p; ++p)
4794 {
4795 if (*p == type)
4796 return p + 1;
4797 if (*p == 'n') /* 'n' is always the last one */
4798 break;
4799 p = vim_strchr(p, ','); /* skip until next ',' */
4800 if (p == NULL) /* hit the end without finding parameter */
4801 break;
4802 }
4803 return NULL;
4804}
4805#endif
4806
4807/*
4808 * Expand environment variables for some string options.
4809 * These string options cannot be indirect!
4810 * If "val" is NULL expand the current value of the option.
4811 * Return pointer to NameBuff, or NULL when not expanded.
4812 */
4813 static char_u *
4814option_expand(opt_idx, val)
4815 int opt_idx;
4816 char_u *val;
4817{
4818 /* if option doesn't need expansion nothing to do */
4819 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4820 return NULL;
4821
4822 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4823 * expand_env() would truncate the string. */
4824 if (val != NULL && STRLEN(val) > MAXPATHL)
4825 return NULL;
4826
4827 if (val == NULL)
4828 val = *(char_u **)options[opt_idx].var;
4829
4830 /*
4831 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4832 * Escape spaces when expanding 'tags', they are used to separate file
4833 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004834 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004835 */
4836 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004837 (char_u **)options[opt_idx].var == &p_tags,
4838#ifdef FEAT_SYN_HL
4839 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4840#endif
4841 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004842 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4843 return NULL;
4844
4845 return NameBuff;
4846}
4847
4848/*
4849 * After setting various option values: recompute variables that depend on
4850 * option values.
4851 */
4852 static void
4853didset_options()
4854{
4855 /* initialize the table for 'iskeyword' et.al. */
4856 (void)init_chartab();
4857
4858 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4859 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4860#ifdef FEAT_SESSION
4861 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4862 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4863#endif
4864#ifdef FEAT_FOLDING
4865 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4866#endif
4867 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4868#ifdef FEAT_VIRTUALEDIT
4869 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4870#endif
4871#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4872 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4873#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004874#ifdef FEAT_SYN_HL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004875 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004876 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004877 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004879#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4880 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4881#endif
4882#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4883 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4884#endif
4885#ifdef FEAT_CMDWIN
4886 /* set cedit_key */
4887 (void)check_cedit();
4888#endif
4889}
4890
4891/*
4892 * Check for string options that are NULL (normally only termcap options).
4893 */
4894 void
4895check_options()
4896{
4897 int opt_idx;
4898
4899 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4900 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4901 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4902}
4903
4904/*
4905 * Check string options in a buffer for NULL value.
4906 */
4907 void
4908check_buf_options(buf)
4909 buf_T *buf;
4910{
4911#if defined(FEAT_QUICKFIX)
4912 check_string_option(&buf->b_p_bh);
4913 check_string_option(&buf->b_p_bt);
4914#endif
4915#ifdef FEAT_MBYTE
4916 check_string_option(&buf->b_p_fenc);
4917#endif
4918 check_string_option(&buf->b_p_ff);
4919#ifdef FEAT_FIND_ID
4920 check_string_option(&buf->b_p_def);
4921 check_string_option(&buf->b_p_inc);
4922# ifdef FEAT_EVAL
4923 check_string_option(&buf->b_p_inex);
4924# endif
4925#endif
4926#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4927 check_string_option(&buf->b_p_inde);
4928 check_string_option(&buf->b_p_indk);
4929#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00004930#if defined(FEAT_EVAL)
4931 check_string_option(&buf->b_p_fex);
4932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004933#ifdef FEAT_CRYPT
4934 check_string_option(&buf->b_p_key);
4935#endif
4936 check_string_option(&buf->b_p_kp);
4937 check_string_option(&buf->b_p_mps);
4938 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004939 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004940 check_string_option(&buf->b_p_isk);
4941#ifdef FEAT_COMMENTS
4942 check_string_option(&buf->b_p_com);
4943#endif
4944#ifdef FEAT_FOLDING
4945 check_string_option(&buf->b_p_cms);
4946#endif
4947 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004948#ifdef FEAT_TEXTOBJ
4949 check_string_option(&buf->b_p_qe);
4950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951#ifdef FEAT_SYN_HL
4952 check_string_option(&buf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004953 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004954 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004955 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004956#endif
4957#ifdef FEAT_SEARCHPATH
4958 check_string_option(&buf->b_p_sua);
4959#endif
4960#ifdef FEAT_CINDENT
4961 check_string_option(&buf->b_p_cink);
4962 check_string_option(&buf->b_p_cino);
4963#endif
4964#ifdef FEAT_AUTOCMD
4965 check_string_option(&buf->b_p_ft);
4966#endif
4967#ifdef FEAT_OSFILETYPE
4968 check_string_option(&buf->b_p_oft);
4969#endif
4970#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4971 check_string_option(&buf->b_p_cinw);
4972#endif
4973#ifdef FEAT_INS_EXPAND
4974 check_string_option(&buf->b_p_cpt);
4975#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004976#ifdef FEAT_COMPL_FUNC
4977 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00004978 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004979#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004980#ifdef FEAT_KEYMAP
4981 check_string_option(&buf->b_p_keymap);
4982#endif
4983#ifdef FEAT_QUICKFIX
4984 check_string_option(&buf->b_p_gp);
4985 check_string_option(&buf->b_p_mp);
4986 check_string_option(&buf->b_p_efm);
4987#endif
4988 check_string_option(&buf->b_p_ep);
4989 check_string_option(&buf->b_p_path);
4990 check_string_option(&buf->b_p_tags);
4991#ifdef FEAT_INS_EXPAND
4992 check_string_option(&buf->b_p_dict);
4993 check_string_option(&buf->b_p_tsr);
4994#endif
4995}
4996
4997/*
4998 * Free the string allocated for an option.
4999 * Checks for the string being empty_option. This may happen if we're out of
5000 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5001 * check_options().
5002 * Does NOT check for P_ALLOCED flag!
5003 */
5004 void
5005free_string_option(p)
5006 char_u *p;
5007{
5008 if (p != empty_option)
5009 vim_free(p);
5010}
5011
5012 void
5013clear_string_option(pp)
5014 char_u **pp;
5015{
5016 if (*pp != empty_option)
5017 vim_free(*pp);
5018 *pp = empty_option;
5019}
5020
5021 static void
5022check_string_option(pp)
5023 char_u **pp;
5024{
5025 if (*pp == NULL)
5026 *pp = empty_option;
5027}
5028
5029/*
5030 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5031 */
5032 void
5033set_term_option_alloced(p)
5034 char_u **p;
5035{
5036 int opt_idx;
5037
5038 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5039 if (options[opt_idx].var == (char_u *)p)
5040 {
5041 options[opt_idx].flags |= P_ALLOCED;
5042 return;
5043 }
5044 return; /* cannot happen: didn't find it! */
5045}
5046
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005047#if defined(FEAT_EVAL) || defined(PROTO)
5048/*
5049 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5050 * Return FALSE when it wasn't.
5051 * Return -1 for an unknown option.
5052 */
5053 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005054was_set_insecurely(opt, opt_flags)
5055 char_u *opt;
5056 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005057{
5058 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005059 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005060
5061 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005062 {
5063 flagp = insecure_flag(idx, opt_flags);
5064 return (*flagp & P_INSECURE) != 0;
5065 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005066 EMSG2(_(e_intern2), "was_set_insecurely()");
5067 return -1;
5068}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005069
5070/*
5071 * Get a pointer to the flags used for the P_INSECURE flag of option
5072 * "opt_idx". For some local options a local flags field is used.
5073 */
5074 static long_u *
5075insecure_flag(opt_idx, opt_flags)
5076 int opt_idx;
5077 int opt_flags;
5078{
5079 if (opt_flags & OPT_LOCAL)
5080 switch ((int)options[opt_idx].indir)
5081 {
5082#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005083 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005084#endif
5085#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005086 case PV_FDE: return &curwin->w_p_fde_flags;
5087 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005088#endif
5089#if defined(FEAT_EVAL)
5090# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005091 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005092# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005093 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005094# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005095 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005096# endif
5097#endif
5098 }
5099
5100 /* Nothing special, return global flags field. */
5101 return &options[opt_idx].flags;
5102}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005103#endif
5104
Bram Moolenaar071d4272004-06-13 20:20:40 +00005105/*
5106 * Set a string option to a new value (without checking the effect).
5107 * The string is copied into allocated memory.
5108 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005109 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5110 * SID_NONE don't set the scriptID. Otherwose set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005112/*ARGSUSED*/
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005114set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005115 char_u *name;
5116 int opt_idx;
5117 char_u *val;
5118 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005119 int set_sid;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120{
5121 char_u *s;
5122 char_u **varp;
5123 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5124
5125 if (opt_idx == -1) /* use name */
5126 {
5127 opt_idx = findoption(name);
5128 if (opt_idx == -1) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005129 {
5130 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005132 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005133 }
5134
5135 if (options[opt_idx].var == NULL) /* can't set hidden option */
5136 return;
5137
5138 s = vim_strsave(val);
5139 if (s != NULL)
5140 {
5141 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5142 both ? OPT_LOCAL : opt_flags);
5143 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
5144 free_string_option(*varp);
5145 *varp = s;
5146
5147 /* For buffer/window local option may also set the global value. */
5148 if (both)
5149 set_string_option_global(opt_idx, varp);
5150
5151 options[opt_idx].flags |= P_ALLOCED;
5152
5153 /* When setting both values of a global option with a local value,
5154 * make the local value empty, so that the global value is used. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005155 if (((int)options[opt_idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156 {
5157 free_string_option(*varp);
5158 *varp = empty_option;
5159 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005160# ifdef FEAT_EVAL
5161 if (set_sid != SID_NONE)
5162 set_option_scriptID_idx(opt_idx, opt_flags,
5163 set_sid == 0 ? current_SID : set_sid);
5164# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165 }
5166}
5167
5168/*
5169 * Set global value for string option when it's a local option.
5170 */
5171 static void
5172set_string_option_global(opt_idx, varp)
5173 int opt_idx; /* option index */
5174 char_u **varp; /* pointer to option variable */
5175{
5176 char_u **p, *s;
5177
5178 /* the global value is always allocated */
5179 if (options[opt_idx].var == VAR_WIN)
5180 p = (char_u **)GLOBAL_WO(varp);
5181 else
5182 p = (char_u **)options[opt_idx].var;
5183 if (options[opt_idx].indir != PV_NONE
5184 && p != varp
5185 && (s = vim_strsave(*varp)) != NULL)
5186 {
5187 free_string_option(*p);
5188 *p = s;
5189 }
5190}
5191
5192/*
5193 * Set a string option to a new value, and handle the effects.
5194 */
5195 static void
5196set_string_option(opt_idx, value, opt_flags)
5197 int opt_idx;
5198 char_u *value;
5199 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5200{
5201 char_u *s;
5202 char_u **varp;
5203 char_u *oldval;
5204
5205 if (options[opt_idx].var == NULL) /* don't set hidden option */
5206 return;
5207
5208 s = vim_strsave(value);
5209 if (s != NULL)
5210 {
5211 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5212 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005213 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 ? OPT_GLOBAL : OPT_LOCAL)
5215 : opt_flags);
5216 oldval = *varp;
5217 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005218 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5219 opt_flags) == NULL)
5220 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221 }
5222}
5223
5224/*
5225 * Handle string options that need some action to perform when changed.
5226 * Returns NULL for success, or an error message for an error.
5227 */
5228 static char_u *
5229did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5230 opt_flags)
5231 int opt_idx; /* index in options[] table */
5232 char_u **varp; /* pointer to the option variable */
5233 int new_value_alloced; /* new value was allocated */
5234 char_u *oldval; /* previous value of the option */
5235 char_u *errbuf; /* buffer for errors, or NULL */
5236 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5237{
5238 char_u *errmsg = NULL;
5239 char_u *s, *p;
5240 int did_chartab = FALSE;
5241 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005242 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005243
5244 /* Get the global option to compare with, otherwise we would have to check
5245 * two values for all local options. */
5246 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5247
5248 /* Disallow changing some options from secure mode */
5249 if ((secure
5250#ifdef HAVE_SANDBOX
5251 || sandbox != 0
5252#endif
5253 ) && (options[opt_idx].flags & P_SECURE))
5254 {
5255 errmsg = e_secure;
5256 }
5257
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005258 /* Check for a "normal" file name in some options. Disallow a path
5259 * separator (slash and/or backslash), wildcards and characters that are
5260 * often illegal in a file name. */
5261 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005262 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005263 {
5264 errmsg = e_invarg;
5265 }
5266
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267 /* 'term' */
5268 else if (varp == &T_NAME)
5269 {
5270 if (T_NAME[0] == NUL)
5271 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5272#ifdef FEAT_GUI
5273 if (gui.in_use)
5274 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5275 else if (term_is_gui(T_NAME))
5276 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5277#endif
5278 else if (set_termname(T_NAME) == FAIL)
5279 errmsg = (char_u *)N_("E522: Not found in termcap");
5280 else
5281 /* Screen colors may have changed. */
5282 redraw_later_clear();
5283 }
5284
5285 /* 'backupcopy' */
5286 else if (varp == &p_bkc)
5287 {
5288 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5289 errmsg = e_invarg;
5290 if (((bkc_flags & BKC_AUTO) != 0)
5291 + ((bkc_flags & BKC_YES) != 0)
5292 + ((bkc_flags & BKC_NO) != 0) != 1)
5293 {
5294 /* Must have exactly one of "auto", "yes" and "no". */
5295 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5296 errmsg = e_invarg;
5297 }
5298 }
5299
5300 /* 'backupext' and 'patchmode' */
5301 else if (varp == &p_bex || varp == &p_pm)
5302 {
5303 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5304 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5305 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5306 }
5307
5308 /*
5309 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5310 * If the new option is invalid, use old value. 'lisp' option: refill
5311 * chartab[] for '-' char
5312 */
5313 else if ( varp == &p_isi
5314 || varp == &(curbuf->b_p_isk)
5315 || varp == &p_isp
5316 || varp == &p_isf)
5317 {
5318 if (init_chartab() == FAIL)
5319 {
5320 did_chartab = TRUE; /* need to restore it below */
5321 errmsg = e_invarg; /* error in value */
5322 }
5323 }
5324
5325 /* 'helpfile' */
5326 else if (varp == &p_hf)
5327 {
5328 /* May compute new values for $VIM and $VIMRUNTIME */
5329 if (didset_vim)
5330 {
5331 vim_setenv((char_u *)"VIM", (char_u *)"");
5332 didset_vim = FALSE;
5333 }
5334 if (didset_vimruntime)
5335 {
5336 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5337 didset_vimruntime = FALSE;
5338 }
5339 }
5340
5341#ifdef FEAT_MULTI_LANG
5342 /* 'helplang' */
5343 else if (varp == &p_hlg)
5344 {
5345 /* Check for "", "ab", "ab,cd", etc. */
5346 for (s = p_hlg; *s != NUL; s += 3)
5347 {
5348 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5349 {
5350 errmsg = e_invarg;
5351 break;
5352 }
5353 if (s[2] == NUL)
5354 break;
5355 }
5356 }
5357#endif
5358
5359 /* 'highlight' */
5360 else if (varp == &p_hl)
5361 {
5362 if (highlight_changed() == FAIL)
5363 errmsg = e_invarg; /* invalid flags */
5364 }
5365
5366 /* 'nrformats' */
5367 else if (gvarp == &p_nf)
5368 {
5369 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5370 errmsg = e_invarg;
5371 }
5372
5373#ifdef FEAT_SESSION
5374 /* 'sessionoptions' */
5375 else if (varp == &p_ssop)
5376 {
5377 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5378 errmsg = e_invarg;
5379 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5380 {
5381 /* Don't allow both "sesdir" and "curdir". */
5382 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5383 errmsg = e_invarg;
5384 }
5385 }
5386 /* 'viewoptions' */
5387 else if (varp == &p_vop)
5388 {
5389 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5390 errmsg = e_invarg;
5391 }
5392#endif
5393
5394 /* 'scrollopt' */
5395#ifdef FEAT_SCROLLBIND
5396 else if (varp == &p_sbo)
5397 {
5398 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5399 errmsg = e_invarg;
5400 }
5401#endif
5402
5403 /* 'ambiwidth' */
5404#ifdef FEAT_MBYTE
5405 else if (varp == &p_ambw)
5406 {
5407 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5408 errmsg = e_invarg;
5409 }
5410#endif
5411
5412 /* 'background' */
5413 else if (varp == &p_bg)
5414 {
5415 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5416 {
5417#ifdef FEAT_EVAL
5418 int dark = (*p_bg == 'd');
5419#endif
5420
5421 init_highlight(FALSE, FALSE);
5422
5423#ifdef FEAT_EVAL
5424 if (dark != (*p_bg == 'd')
5425 && get_var_value((char_u *)"g:colors_name") != NULL)
5426 {
5427 /* The color scheme must have set 'background' back to another
5428 * value, that's not what we want here. Disable the color
5429 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005430 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431 free_string_option(p_bg);
5432 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5433 check_string_option(&p_bg);
5434 init_highlight(FALSE, FALSE);
5435 }
5436#endif
5437 }
5438 else
5439 errmsg = e_invarg;
5440 }
5441
5442 /* 'wildmode' */
5443 else if (varp == &p_wim)
5444 {
5445 if (check_opt_wim() == FAIL)
5446 errmsg = e_invarg;
5447 }
5448
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005449#ifdef FEAT_CMDL_COMPL
5450 /* 'wildoptions' */
5451 else if (varp == &p_wop)
5452 {
5453 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5454 errmsg = e_invarg;
5455 }
5456#endif
5457
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458#ifdef FEAT_WAK
5459 /* 'winaltkeys' */
5460 else if (varp == &p_wak)
5461 {
5462 if (*p_wak == NUL
5463 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5464 errmsg = e_invarg;
5465# ifdef FEAT_MENU
5466# ifdef FEAT_GUI_MOTIF
5467 else if (gui.in_use)
5468 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5469# else
5470# ifdef FEAT_GUI_GTK
5471 else if (gui.in_use)
5472 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5473# endif
5474# endif
5475# endif
5476 }
5477#endif
5478
5479#ifdef FEAT_AUTOCMD
5480 /* 'eventignore' */
5481 else if (varp == &p_ei)
5482 {
5483 if (check_ei() == FAIL)
5484 errmsg = e_invarg;
5485 }
5486#endif
5487
5488#ifdef FEAT_MBYTE
5489 /* 'encoding' and 'fileencoding' */
5490 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5491 {
5492 if (gvarp == &p_fenc)
5493 {
5494 if (!curbuf->b_p_ma)
5495 errmsg = e_modifiable;
5496 else if (vim_strchr(*varp, ',') != NULL)
5497 /* No comma allowed in 'fileencoding'; catches confusing it
5498 * with 'fileencodings'. */
5499 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005501 {
5502# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503 /* May show a "+" in the title now. */
5504 need_maketitle = TRUE;
5505# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005506 /* Add 'fileencoding' to the swap file. */
5507 ml_setflags(curbuf);
5508 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509 }
5510 if (errmsg == NULL)
5511 {
5512 /* canonize the value, so that STRCMP() can be used on it */
5513 p = enc_canonize(*varp);
5514 if (p != NULL)
5515 {
5516 vim_free(*varp);
5517 *varp = p;
5518 }
5519 if (varp == &p_enc)
5520 {
5521 errmsg = mb_init();
5522# ifdef FEAT_TITLE
5523 need_maketitle = TRUE;
5524# endif
5525 }
5526 }
5527
5528# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5529 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5530 {
5531 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5532 if (STRCMP(p_tenc, "utf-8") != 0)
5533 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5534 }
5535# endif
5536
5537 if (errmsg == NULL)
5538 {
5539# ifdef FEAT_KEYMAP
5540 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5541 * (with another encoding). */
5542 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5543 (void)keymap_init();
5544# endif
5545
5546 /* When 'termencoding' is not empty and 'encoding' changes or when
5547 * 'termencoding' changes, need to setup for keyboard input and
5548 * display output conversion. */
5549 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5550 {
5551 convert_setup(&input_conv, p_tenc, p_enc);
5552 convert_setup(&output_conv, p_enc, p_tenc);
5553 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005554
5555# if defined(WIN3264) && defined(FEAT_MBYTE)
5556 /* $HOME may have characters in active code page. */
5557 if (varp == &p_enc)
5558 init_homedir();
5559# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005560 }
5561 }
5562#endif
5563
5564#if defined(FEAT_POSTSCRIPT)
5565 else if (varp == &p_penc)
5566 {
5567 /* Canonize printencoding if VIM standard one */
5568 p = enc_canonize(p_penc);
5569 if (p != NULL)
5570 {
5571 vim_free(p_penc);
5572 p_penc = p;
5573 }
5574 else
5575 {
5576 /* Ensure lower case and '-' for '_' */
5577 for (s = p_penc; *s != NUL; s++)
5578 {
5579 if (*s == '_')
5580 *s = '-';
5581 else
5582 *s = TOLOWER_ASC(*s);
5583 }
5584 }
5585 }
5586#endif
5587
Bram Moolenaar9372a112005-12-06 19:59:18 +00005588#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589 else if (varp == &p_imak)
5590 {
5591 if (gui.in_use && !im_xim_isvalid_imactivate())
5592 errmsg = e_invarg;
5593 }
5594#endif
5595
5596#ifdef FEAT_KEYMAP
5597 else if (varp == &curbuf->b_p_keymap)
5598 {
5599 /* load or unload key mapping tables */
5600 errmsg = keymap_init();
5601
5602 /* When successfully installed a new keymap switch on using it. */
5603 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5604 {
5605 curbuf->b_p_iminsert = B_IMODE_LMAP;
5606 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5607 curbuf->b_p_imsearch = B_IMODE_LMAP;
5608 set_iminsert_global();
5609 set_imsearch_global();
5610# ifdef FEAT_WINDOWS
5611 status_redraw_curbuf();
5612# endif
5613 }
5614 }
5615#endif
5616
5617 /* 'fileformat' */
5618 else if (gvarp == &p_ff)
5619 {
5620 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5621 errmsg = e_modifiable;
5622 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5623 errmsg = e_invarg;
5624 else
5625 {
5626 /* may also change 'textmode' */
5627 if (get_fileformat(curbuf) == EOL_DOS)
5628 curbuf->b_p_tx = TRUE;
5629 else
5630 curbuf->b_p_tx = FALSE;
5631#ifdef FEAT_TITLE
5632 need_maketitle = TRUE;
5633#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005634 /* update flag in swap file */
5635 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636 }
5637 }
5638
5639 /* 'fileformats' */
5640 else if (varp == &p_ffs)
5641 {
5642 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5643 errmsg = e_invarg;
5644 else
5645 {
5646 /* also change 'textauto' */
5647 if (*p_ffs == NUL)
5648 p_ta = FALSE;
5649 else
5650 p_ta = TRUE;
5651 }
5652 }
5653
5654#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5655 /* 'cryptkey' */
5656 else if (gvarp == &p_key)
5657 {
5658 /* Make sure the ":set" command doesn't show the new value in the
5659 * history. */
5660 remove_key_from_history();
5661 }
5662#endif
5663
5664 /* 'matchpairs' */
5665 else if (gvarp == &p_mps)
5666 {
5667 /* Check for "x:y,x:y" */
5668 for (p = *varp; *p != NUL; p += 4)
5669 {
5670 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5671 {
5672 errmsg = e_invarg;
5673 break;
5674 }
5675 if (p[3] == NUL)
5676 break;
5677 }
5678 }
5679
5680#ifdef FEAT_COMMENTS
5681 /* 'comments' */
5682 else if (gvarp == &p_com)
5683 {
5684 for (s = *varp; *s; )
5685 {
5686 while (*s && *s != ':')
5687 {
5688 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5689 && !VIM_ISDIGIT(*s) && *s != '-')
5690 {
5691 errmsg = illegal_char(errbuf, *s);
5692 break;
5693 }
5694 ++s;
5695 }
5696 if (*s++ == NUL)
5697 errmsg = (char_u *)N_("E524: Missing colon");
5698 else if (*s == ',' || *s == NUL)
5699 errmsg = (char_u *)N_("E525: Zero length string");
5700 if (errmsg != NULL)
5701 break;
5702 while (*s && *s != ',')
5703 {
5704 if (*s == '\\' && s[1] != NUL)
5705 ++s;
5706 ++s;
5707 }
5708 s = skip_to_option_part(s);
5709 }
5710 }
5711#endif
5712
5713 /* 'listchars' */
5714 else if (varp == &p_lcs)
5715 {
5716 errmsg = set_chars_option(varp);
5717 }
5718
5719#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5720 /* 'fillchars' */
5721 else if (varp == &p_fcs)
5722 {
5723 errmsg = set_chars_option(varp);
5724 }
5725#endif
5726
5727#ifdef FEAT_CMDWIN
5728 /* 'cedit' */
5729 else if (varp == &p_cedit)
5730 {
5731 errmsg = check_cedit();
5732 }
5733#endif
5734
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005735 /* 'verbosefile' */
5736 else if (varp == &p_vfile)
5737 {
5738 verbose_stop();
5739 if (*p_vfile != NUL && verbose_open() == FAIL)
5740 errmsg = e_invarg;
5741 }
5742
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743#ifdef FEAT_VIMINFO
5744 /* 'viminfo' */
5745 else if (varp == &p_viminfo)
5746 {
5747 for (s = p_viminfo; *s;)
5748 {
5749 /* Check it's a valid character */
5750 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5751 {
5752 errmsg = illegal_char(errbuf, *s);
5753 break;
5754 }
5755 if (*s == 'n') /* name is always last one */
5756 {
5757 break;
5758 }
5759 else if (*s == 'r') /* skip until next ',' */
5760 {
5761 while (*++s && *s != ',')
5762 ;
5763 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005764 else if (*s == '%')
5765 {
5766 /* optional number */
5767 while (vim_isdigit(*++s))
5768 ;
5769 }
5770 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005771 ++s; /* no extra chars */
5772 else /* must have a number */
5773 {
5774 while (vim_isdigit(*++s))
5775 ;
5776
5777 if (!VIM_ISDIGIT(*(s - 1)))
5778 {
5779 if (errbuf != NULL)
5780 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005781 sprintf((char *)errbuf,
5782 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783 transchar_byte(*(s - 1)));
5784 errmsg = errbuf;
5785 }
5786 else
5787 errmsg = (char_u *)"";
5788 break;
5789 }
5790 }
5791 if (*s == ',')
5792 ++s;
5793 else if (*s)
5794 {
5795 if (errbuf != NULL)
5796 errmsg = (char_u *)N_("E527: Missing comma");
5797 else
5798 errmsg = (char_u *)"";
5799 break;
5800 }
5801 }
5802 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5803 errmsg = (char_u *)N_("E528: Must specify a ' value");
5804 }
5805#endif /* FEAT_VIMINFO */
5806
5807 /* terminal options */
5808 else if (istermoption(&options[opt_idx]) && full_screen)
5809 {
5810 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5811 if (varp == &T_CCO)
5812 {
5813 t_colors = atoi((char *)T_CCO);
5814 if (t_colors <= 1)
5815 {
5816 if (new_value_alloced)
5817 vim_free(T_CCO);
5818 T_CCO = empty_option;
5819 }
5820 /* We now have a different color setup, initialize it again. */
5821 init_highlight(TRUE, FALSE);
5822 }
5823 ttest(FALSE);
5824 if (varp == &T_ME)
5825 {
5826 out_str(T_ME);
5827 redraw_later(CLEAR);
5828#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5829 /* Since t_me has been set, this probably means that the user
5830 * wants to use this as default colors. Need to reset default
5831 * background/foreground colors. */
5832 mch_set_normal_colors();
5833#endif
5834 }
5835 }
5836
5837#ifdef FEAT_LINEBREAK
5838 /* 'showbreak' */
5839 else if (varp == &p_sbr)
5840 {
5841 for (s = p_sbr; *s; )
5842 {
5843 if (ptr2cells(s) != 1)
5844 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005845 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 }
5847 }
5848#endif
5849
5850#ifdef FEAT_GUI
5851 /* 'guifont' */
5852 else if (varp == &p_guifont)
5853 {
5854 if (gui.in_use)
5855 {
5856 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005857# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858 /*
5859 * Put up a font dialog and let the user select a new value.
5860 * If this is cancelled go back to the old value but don't
5861 * give an error message.
5862 */
5863 if (STRCMP(p, "*") == 0)
5864 {
5865 p = gui_mch_font_dialog(oldval);
5866
5867 if (new_value_alloced)
5868 free_string_option(p_guifont);
5869
5870 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5871 new_value_alloced = TRUE;
5872 }
5873# endif
5874 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5875 {
5876# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5877 if (STRCMP(p_guifont, "*") == 0)
5878 {
5879 /* Dialog was cancelled: Keep the old value without giving
5880 * an error message. */
5881 if (new_value_alloced)
5882 free_string_option(p_guifont);
5883 p_guifont = vim_strsave(oldval);
5884 new_value_alloced = TRUE;
5885 }
5886 else
5887# endif
5888 errmsg = (char_u *)N_("E596: Invalid font(s)");
5889 }
5890 }
5891 }
5892# ifdef FEAT_XFONTSET
5893 else if (varp == &p_guifontset)
5894 {
5895 if (STRCMP(p_guifontset, "*") == 0)
5896 errmsg = (char_u *)N_("E597: can't select fontset");
5897 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5898 errmsg = (char_u *)N_("E598: Invalid fontset");
5899 }
5900# endif
5901# ifdef FEAT_MBYTE
5902 else if (varp == &p_guifontwide)
5903 {
5904 if (STRCMP(p_guifontwide, "*") == 0)
5905 errmsg = (char_u *)N_("E533: can't select wide font");
5906 else if (gui_get_wide_font() == FAIL)
5907 errmsg = (char_u *)N_("E534: Invalid wide font");
5908 }
5909# endif
5910#endif
5911
5912#ifdef CURSOR_SHAPE
5913 /* 'guicursor' */
5914 else if (varp == &p_guicursor)
5915 errmsg = parse_shape_opt(SHAPE_CURSOR);
5916#endif
5917
5918#ifdef FEAT_MOUSESHAPE
5919 /* 'mouseshape' */
5920 else if (varp == &p_mouseshape)
5921 {
5922 errmsg = parse_shape_opt(SHAPE_MOUSE);
5923 update_mouseshape(-1);
5924 }
5925#endif
5926
5927#ifdef FEAT_PRINTER
5928 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005929 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005930# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005931 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005932 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005933# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934#endif
5935
5936#ifdef FEAT_LANGMAP
5937 /* 'langmap' */
5938 else if (varp == &p_langmap)
5939 langmap_set();
5940#endif
5941
5942#ifdef FEAT_LINEBREAK
5943 /* 'breakat' */
5944 else if (varp == &p_breakat)
5945 fill_breakat_flags();
5946#endif
5947
5948#ifdef FEAT_TITLE
5949 /* 'titlestring' and 'iconstring' */
5950 else if (varp == &p_titlestring || varp == &p_iconstring)
5951 {
5952# ifdef FEAT_STL_OPT
5953 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5954
5955 /* NULL => statusline syntax */
5956 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5957 stl_syntax |= flagval;
5958 else
5959 stl_syntax &= ~flagval;
5960# endif
5961 did_set_title(varp == &p_iconstring);
5962
5963 }
5964#endif
5965
5966#ifdef FEAT_GUI
5967 /* 'guioptions' */
5968 else if (varp == &p_go)
5969 gui_init_which_components(oldval);
5970#endif
5971
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00005972#if defined(FEAT_GUI_TABLINE)
5973 /* 'guitablabel' */
5974 else if (varp == &p_gtl)
5975 gui_update_tabline();
5976#endif
5977
Bram Moolenaar071d4272004-06-13 20:20:40 +00005978#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5979 /* 'ttymouse' */
5980 else if (varp == &p_ttym)
5981 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005982 /* Switch the mouse off before changing the escape sequences used for
5983 * that. */
5984 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005985 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5986 errmsg = e_invarg;
5987 else
5988 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005989 if (termcap_active)
5990 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 }
5992#endif
5993
5994#ifdef FEAT_VISUAL
5995 /* 'selection' */
5996 else if (varp == &p_sel)
5997 {
5998 if (*p_sel == NUL
5999 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6000 errmsg = e_invarg;
6001 }
6002
6003 /* 'selectmode' */
6004 else if (varp == &p_slm)
6005 {
6006 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6007 errmsg = e_invarg;
6008 }
6009#endif
6010
6011#ifdef FEAT_BROWSE
6012 /* 'browsedir' */
6013 else if (varp == &p_bsdir)
6014 {
6015 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6016 && !mch_isdir(p_bsdir))
6017 errmsg = e_invarg;
6018 }
6019#endif
6020
6021#ifdef FEAT_VISUAL
6022 /* 'keymodel' */
6023 else if (varp == &p_km)
6024 {
6025 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6026 errmsg = e_invarg;
6027 else
6028 {
6029 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6030 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6031 }
6032 }
6033#endif
6034
6035 /* 'mousemodel' */
6036 else if (varp == &p_mousem)
6037 {
6038 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6039 errmsg = e_invarg;
6040#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6041 else if (*p_mousem != *oldval)
6042 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6043 * to create or delete the popup menus. */
6044 gui_motif_update_mousemodel(root_menu);
6045#endif
6046 }
6047
6048 /* 'switchbuf' */
6049 else if (varp == &p_swb)
6050 {
6051 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
6052 errmsg = e_invarg;
6053 }
6054
6055 /* 'debug' */
6056 else if (varp == &p_debug)
6057 {
6058 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
6059 errmsg = e_invarg;
6060 }
6061
6062 /* 'display' */
6063 else if (varp == &p_dy)
6064 {
6065 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6066 errmsg = e_invarg;
6067 else
6068 (void)init_chartab();
6069
6070 }
6071
6072#ifdef FEAT_VERTSPLIT
6073 /* 'eadirection' */
6074 else if (varp == &p_ead)
6075 {
6076 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6077 errmsg = e_invarg;
6078 }
6079#endif
6080
6081#ifdef FEAT_CLIPBOARD
6082 /* 'clipboard' */
6083 else if (varp == &p_cb)
6084 errmsg = check_clipboard_option();
6085#endif
6086
Bram Moolenaar217ad922005-03-20 22:37:15 +00006087#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006088 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6089 * buffer in which 'spell' is set load the wordlists. */
6090 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006091 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006092 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006093 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006094
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006095 if (varp == &(curbuf->b_p_spf))
6096 {
6097 l = STRLEN(curbuf->b_p_spf);
6098 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6099 ".add") != 0))
6100 errmsg = e_invarg;
6101 }
6102
6103 if (errmsg == NULL)
6104 {
6105 FOR_ALL_WINDOWS(wp)
6106 if (wp->w_buffer == curbuf && wp->w_p_spell)
6107 {
6108 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006109# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006110 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006111# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006112 }
6113 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006114 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006115 /* When 'spellcapcheck' is set compile the regexp program. */
6116 else if (varp == &(curbuf->b_p_spc))
6117 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006118 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006119 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006120 /* 'spellsuggest' */
6121 else if (varp == &p_sps)
6122 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006123 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006124 errmsg = e_invarg;
6125 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006126 /* 'mkspellmem' */
6127 else if (varp == &p_msm)
6128 {
6129 if (spell_check_msm() != OK)
6130 errmsg = e_invarg;
6131 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006132#endif
6133
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134#ifdef FEAT_QUICKFIX
6135 /* When 'bufhidden' is set, check for valid value. */
6136 else if (gvarp == &p_bh)
6137 {
6138 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6139 errmsg = e_invarg;
6140 }
6141
6142 /* When 'buftype' is set, check for valid value. */
6143 else if (gvarp == &p_bt)
6144 {
6145 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6146 errmsg = e_invarg;
6147 else
6148 {
6149# ifdef FEAT_WINDOWS
6150 if (curwin->w_status_height)
6151 {
6152 curwin->w_redr_status = TRUE;
6153 redraw_later(VALID);
6154 }
6155# endif
6156 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6157 }
6158 }
6159#endif
6160
6161#ifdef FEAT_STL_OPT
6162 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006163 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006164 {
6165 int wid;
6166
6167 if (varp == &p_ruf) /* reset ru_wid first */
6168 ru_wid = 0;
6169 s = *varp;
6170 if (varp == &p_ruf && *s == '%')
6171 {
6172 /* set ru_wid if 'ruf' starts with "%99(" */
6173 if (*++s == '-') /* ignore a '-' */
6174 s++;
6175 wid = getdigits(&s);
6176 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6177 ru_wid = wid;
6178 else
6179 errmsg = check_stl_option(p_ruf);
6180 }
6181 else
6182 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006183 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 comp_col();
6185 }
6186#endif
6187
6188#ifdef FEAT_INS_EXPAND
6189 /* check if it is a valid value for 'complete' -- Acevedo */
6190 else if (gvarp == &p_cpt)
6191 {
6192 for (s = *varp; *s;)
6193 {
6194 while(*s == ',' || *s == ' ')
6195 s++;
6196 if (!*s)
6197 break;
6198 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6199 {
6200 errmsg = illegal_char(errbuf, *s);
6201 break;
6202 }
6203 if (*++s != NUL && *s != ',' && *s != ' ')
6204 {
6205 if (s[-1] == 'k' || s[-1] == 's')
6206 {
6207 /* skip optional filename after 'k' and 's' */
6208 while (*s && *s != ',' && *s != ' ')
6209 {
6210 if (*s == '\\')
6211 ++s;
6212 ++s;
6213 }
6214 }
6215 else
6216 {
6217 if (errbuf != NULL)
6218 {
6219 sprintf((char *)errbuf,
6220 _("E535: Illegal character after <%c>"),
6221 *--s);
6222 errmsg = errbuf;
6223 }
6224 else
6225 errmsg = (char_u *)"";
6226 break;
6227 }
6228 }
6229 }
6230 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006231
6232 /* 'completeopt' */
6233 else if (varp == &p_cot)
6234 {
6235 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6236 errmsg = e_invarg;
6237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006238#endif /* FEAT_INS_EXPAND */
6239
6240
6241#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6242 else if (varp == &p_toolbar)
6243 {
6244 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6245 &toolbar_flags, TRUE) != OK)
6246 errmsg = e_invarg;
6247 else
6248 {
6249 out_flush();
6250 gui_mch_show_toolbar((toolbar_flags &
6251 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6252 }
6253 }
6254#endif
6255
6256#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6257 /* 'toolbariconsize': GTK+ 2 only */
6258 else if (varp == &p_tbis)
6259 {
6260 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6261 errmsg = e_invarg;
6262 else
6263 {
6264 out_flush();
6265 gui_mch_show_toolbar((toolbar_flags &
6266 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6267 }
6268 }
6269#endif
6270
6271 /* 'pastetoggle': translate key codes like in a mapping */
6272 else if (varp == &p_pt)
6273 {
6274 if (*p_pt)
6275 {
6276 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6277 if (p != NULL)
6278 {
6279 if (new_value_alloced)
6280 free_string_option(p_pt);
6281 p_pt = p;
6282 new_value_alloced = TRUE;
6283 }
6284 }
6285 }
6286
6287 /* 'backspace' */
6288 else if (varp == &p_bs)
6289 {
6290 if (VIM_ISDIGIT(*p_bs))
6291 {
6292 if (*p_bs >'2' || p_bs[1] != NUL)
6293 errmsg = e_invarg;
6294 }
6295 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6296 errmsg = e_invarg;
6297 }
6298
6299 /* 'casemap' */
6300 else if (varp == &p_cmp)
6301 {
6302 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6303 errmsg = e_invarg;
6304 }
6305
6306#ifdef FEAT_DIFF
6307 /* 'diffopt' */
6308 else if (varp == &p_dip)
6309 {
6310 if (diffopt_changed() == FAIL)
6311 errmsg = e_invarg;
6312 }
6313#endif
6314
6315#ifdef FEAT_FOLDING
6316 /* 'foldmethod' */
6317 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6318 {
6319 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6320 || *curwin->w_p_fdm == NUL)
6321 errmsg = e_invarg;
6322 else
6323 foldUpdateAll(curwin);
6324 }
6325# ifdef FEAT_EVAL
6326 /* 'foldexpr' */
6327 else if (varp == &curwin->w_p_fde)
6328 {
6329 if (foldmethodIsExpr(curwin))
6330 foldUpdateAll(curwin);
6331 }
6332# endif
6333 /* 'foldmarker' */
6334 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6335 {
6336 p = vim_strchr(*varp, ',');
6337 if (p == NULL)
6338 errmsg = (char_u *)N_("E536: comma required");
6339 else if (p == *varp || p[1] == NUL)
6340 errmsg = e_invarg;
6341 else if (foldmethodIsMarker(curwin))
6342 foldUpdateAll(curwin);
6343 }
6344 /* 'commentstring' */
6345 else if (gvarp == &p_cms)
6346 {
6347 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6348 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6349 }
6350 /* 'foldopen' */
6351 else if (varp == &p_fdo)
6352 {
6353 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6354 errmsg = e_invarg;
6355 }
6356 /* 'foldclose' */
6357 else if (varp == &p_fcl)
6358 {
6359 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6360 errmsg = e_invarg;
6361 }
6362#endif
6363
6364#ifdef FEAT_VIRTUALEDIT
6365 /* 'virtualedit' */
6366 else if (varp == &p_ve)
6367 {
6368 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6369 errmsg = e_invarg;
6370 else if (STRCMP(p_ve, oldval) != 0)
6371 {
6372 /* Recompute cursor position in case the new 've' setting
6373 * changes something. */
6374 validate_virtcol();
6375 coladvance(curwin->w_virtcol);
6376 }
6377 }
6378#endif
6379
6380#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6381 else if (varp == &p_csqf)
6382 {
6383 if (p_csqf != NULL)
6384 {
6385 p = p_csqf;
6386 while (*p != NUL)
6387 {
6388 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6389 || p[1] == NUL
6390 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6391 || (p[2] != NUL && p[2] != ','))
6392 {
6393 errmsg = e_invarg;
6394 break;
6395 }
6396 else if (p[2] == NUL)
6397 break;
6398 else
6399 p += 3;
6400 }
6401 }
6402 }
6403#endif
6404
6405 /* Options that are a list of flags. */
6406 else
6407 {
6408 p = NULL;
6409 if (varp == &p_ww)
6410 p = (char_u *)WW_ALL;
6411 if (varp == &p_shm)
6412 p = (char_u *)SHM_ALL;
6413 else if (varp == &(p_cpo))
6414 p = (char_u *)CPO_ALL;
6415 else if (varp == &(curbuf->b_p_fo))
6416 p = (char_u *)FO_ALL;
6417 else if (varp == &p_mouse)
6418 {
6419#ifdef FEAT_MOUSE
6420 p = (char_u *)MOUSE_ALL;
6421#else
6422 if (*p_mouse != NUL)
6423 errmsg = (char_u *)N_("E538: No mouse support");
6424#endif
6425 }
6426#if defined(FEAT_GUI)
6427 else if (varp == &p_go)
6428 p = (char_u *)GO_ALL;
6429#endif
6430 if (p != NULL)
6431 {
6432 for (s = *varp; *s; ++s)
6433 if (vim_strchr(p, *s) == NULL)
6434 {
6435 errmsg = illegal_char(errbuf, *s);
6436 break;
6437 }
6438 }
6439 }
6440
6441 /*
6442 * If error detected, restore the previous value.
6443 */
6444 if (errmsg != NULL)
6445 {
6446 if (new_value_alloced)
6447 free_string_option(*varp);
6448 *varp = oldval;
6449 /*
6450 * When resetting some values, need to act on it.
6451 */
6452 if (did_chartab)
6453 (void)init_chartab();
6454 if (varp == &p_hl)
6455 (void)highlight_changed();
6456 }
6457 else
6458 {
6459#ifdef FEAT_EVAL
6460 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006461 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006462#endif
6463 /*
6464 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006465 * Use "free_oldval", because recursiveness may change the flags under
6466 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006468 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469 free_string_option(oldval);
6470 if (new_value_alloced)
6471 options[opt_idx].flags |= P_ALLOCED;
6472 else
6473 options[opt_idx].flags &= ~P_ALLOCED;
6474
6475 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006476 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 {
6478 /* global option with local value set to use global value; free
6479 * the local value and make it empty */
6480 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6481 free_string_option(*(char_u **)p);
6482 *(char_u **)p = empty_option;
6483 }
6484
6485 /* May set global value for local option. */
6486 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6487 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006488
6489#ifdef FEAT_AUTOCMD
6490 /*
6491 * Trigger the autocommand only after setting the flags.
6492 */
6493# ifdef FEAT_SYN_HL
6494 /* When 'syntax' is set, load the syntax of that name */
6495 if (varp == &(curbuf->b_p_syn))
6496 {
6497 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6498 curbuf->b_fname, TRUE, curbuf);
6499 }
6500# endif
6501 else if (varp == &(curbuf->b_p_ft))
6502 {
6503 /* 'filetype' is set, trigger the FileType autocommand */
6504 did_filetype = TRUE;
6505 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6506 curbuf->b_fname, TRUE, curbuf);
6507 }
6508#endif
6509#ifdef FEAT_SYN_HL
6510 if (varp == &(curbuf->b_p_spl))
6511 {
6512 char_u fname[200];
6513
6514 /*
6515 * Source the spell/LANG.vim in 'runtimepath'.
6516 * They could set 'spellcapcheck' depending on the language.
6517 * Use the first name in 'spelllang' up to '_region' or
6518 * '.encoding'.
6519 */
6520 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6521 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6522 break;
6523 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6524 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6525 source_runtime(fname, TRUE);
6526 }
6527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006528 }
6529
6530#ifdef FEAT_MOUSE
6531 if (varp == &p_mouse)
6532 {
6533# ifdef FEAT_MOUSE_TTY
6534 if (*p_mouse == NUL)
6535 mch_setmouse(FALSE); /* switch mouse off */
6536 else
6537# endif
6538 setmouse(); /* in case 'mouse' changed */
6539 }
6540#endif
6541
6542 if (curwin->w_curswant != MAXCOL)
6543 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6544 check_redraw(options[opt_idx].flags);
6545
6546 return errmsg;
6547}
6548
6549/*
6550 * Handle setting 'listchars' or 'fillchars'.
6551 * Returns error message, NULL if it's OK.
6552 */
6553 static char_u *
6554set_chars_option(varp)
6555 char_u **varp;
6556{
6557 int round, i, len, entries;
6558 char_u *p, *s;
6559 int c1, c2 = 0;
6560 struct charstab
6561 {
6562 int *cp;
6563 char *name;
6564 };
6565#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6566 static struct charstab filltab[] =
6567 {
6568 {&fill_stl, "stl"},
6569 {&fill_stlnc, "stlnc"},
6570 {&fill_vert, "vert"},
6571 {&fill_fold, "fold"},
6572 {&fill_diff, "diff"},
6573 };
6574#endif
6575 static struct charstab lcstab[] =
6576 {
6577 {&lcs_eol, "eol"},
6578 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006579 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006580 {&lcs_prec, "precedes"},
6581 {&lcs_tab2, "tab"},
6582 {&lcs_trail, "trail"},
6583 };
6584 struct charstab *tab;
6585
6586#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6587 if (varp == &p_lcs)
6588#endif
6589 {
6590 tab = lcstab;
6591 entries = sizeof(lcstab) / sizeof(struct charstab);
6592 }
6593#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6594 else
6595 {
6596 tab = filltab;
6597 entries = sizeof(filltab) / sizeof(struct charstab);
6598 }
6599#endif
6600
6601 /* first round: check for valid value, second round: assign values */
6602 for (round = 0; round <= 1; ++round)
6603 {
6604 if (round)
6605 {
6606 /* After checking that the value is valid: set defaults: space for
6607 * 'fillchars', NUL for 'listchars' */
6608 for (i = 0; i < entries; ++i)
6609 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6610 if (varp == &p_lcs)
6611 lcs_tab1 = NUL;
6612#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6613 else
6614 fill_diff = '-';
6615#endif
6616 }
6617 p = *varp;
6618 while (*p)
6619 {
6620 for (i = 0; i < entries; ++i)
6621 {
6622 len = (int)STRLEN(tab[i].name);
6623 if (STRNCMP(p, tab[i].name, len) == 0
6624 && p[len] == ':'
6625 && p[len + 1] != NUL)
6626 {
6627 s = p + len + 1;
6628#ifdef FEAT_MBYTE
6629 c1 = mb_ptr2char_adv(&s);
6630#else
6631 c1 = *s++;
6632#endif
6633 if (tab[i].cp == &lcs_tab2)
6634 {
6635 if (*s == NUL)
6636 continue;
6637#ifdef FEAT_MBYTE
6638 c2 = mb_ptr2char_adv(&s);
6639#else
6640 c2 = *s++;
6641#endif
6642 }
6643 if (*s == ',' || *s == NUL)
6644 {
6645 if (round)
6646 {
6647 if (tab[i].cp == &lcs_tab2)
6648 {
6649 lcs_tab1 = c1;
6650 lcs_tab2 = c2;
6651 }
6652 else
6653 *(tab[i].cp) = c1;
6654
6655 }
6656 p = s;
6657 break;
6658 }
6659 }
6660 }
6661
6662 if (i == entries)
6663 return e_invarg;
6664 if (*p == ',')
6665 ++p;
6666 }
6667 }
6668
6669 return NULL; /* no error */
6670}
6671
6672#ifdef FEAT_STL_OPT
6673/*
6674 * Check validity of options with the 'statusline' format.
6675 * Return error message or NULL.
6676 */
6677 char_u *
6678check_stl_option(s)
6679 char_u *s;
6680{
6681 int itemcnt = 0;
6682 int groupdepth = 0;
6683 static char_u errbuf[80];
6684
6685 while (*s && itemcnt < STL_MAX_ITEM)
6686 {
6687 /* Check for valid keys after % sequences */
6688 while (*s && *s != '%')
6689 s++;
6690 if (!*s)
6691 break;
6692 s++;
6693 if (*s != '%' && *s != ')')
6694 ++itemcnt;
6695 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6696 {
6697 s++;
6698 continue;
6699 }
6700 if (*s == ')')
6701 {
6702 s++;
6703 if (--groupdepth < 0)
6704 break;
6705 continue;
6706 }
6707 if (*s == '-')
6708 s++;
6709 while (VIM_ISDIGIT(*s))
6710 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006711 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006712 continue;
6713 if (*s == '.')
6714 {
6715 s++;
6716 while (*s && VIM_ISDIGIT(*s))
6717 s++;
6718 }
6719 if (*s == '(')
6720 {
6721 groupdepth++;
6722 continue;
6723 }
6724 if (vim_strchr(STL_ALL, *s) == NULL)
6725 {
6726 return illegal_char(errbuf, *s);
6727 }
6728 if (*s == '{')
6729 {
6730 s++;
6731 while (*s != '}' && *s)
6732 s++;
6733 if (*s != '}')
6734 return (char_u *)N_("E540: Unclosed expression sequence");
6735 }
6736 }
6737 if (itemcnt >= STL_MAX_ITEM)
6738 return (char_u *)N_("E541: too many items");
6739 if (groupdepth != 0)
6740 return (char_u *)N_("E542: unbalanced groups");
6741 return NULL;
6742}
6743#endif
6744
6745#ifdef FEAT_CLIPBOARD
6746/*
6747 * Extract the items in the 'clipboard' option and set global values.
6748 */
6749 static char_u *
6750check_clipboard_option()
6751{
6752 int new_unnamed = FALSE;
6753 int new_autoselect = FALSE;
6754 int new_autoselectml = FALSE;
6755 regprog_T *new_exclude_prog = NULL;
6756 char_u *errmsg = NULL;
6757 char_u *p;
6758
6759 for (p = p_cb; *p != NUL; )
6760 {
6761 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6762 {
6763 new_unnamed = TRUE;
6764 p += 7;
6765 }
6766 else if (STRNCMP(p, "autoselect", 10) == 0
6767 && (p[10] == ',' || p[10] == NUL))
6768 {
6769 new_autoselect = TRUE;
6770 p += 10;
6771 }
6772 else if (STRNCMP(p, "autoselectml", 12) == 0
6773 && (p[12] == ',' || p[12] == NUL))
6774 {
6775 new_autoselectml = TRUE;
6776 p += 12;
6777 }
6778 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6779 {
6780 p += 8;
6781 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6782 if (new_exclude_prog == NULL)
6783 errmsg = e_invarg;
6784 break;
6785 }
6786 else
6787 {
6788 errmsg = e_invarg;
6789 break;
6790 }
6791 if (*p == ',')
6792 ++p;
6793 }
6794 if (errmsg == NULL)
6795 {
6796 clip_unnamed = new_unnamed;
6797 clip_autoselect = new_autoselect;
6798 clip_autoselectml = new_autoselectml;
6799 vim_free(clip_exclude_prog);
6800 clip_exclude_prog = new_exclude_prog;
6801 }
6802 else
6803 vim_free(new_exclude_prog);
6804
6805 return errmsg;
6806}
6807#endif
6808
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006809#ifdef FEAT_SYN_HL
6810/*
6811 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6812 * Return error message when failed, NULL when OK.
6813 */
6814 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006815compile_cap_prog(buf)
6816 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006817{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006818 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006819 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006820
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006821 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006822 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006823 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006824 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006825 /* Prepend a ^ so that we only match at one column */
6826 re = concat_str((char_u *)"^", buf->b_p_spc);
6827 if (re != NULL)
6828 {
6829 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6830 if (buf->b_cap_prog == NULL)
6831 {
6832 buf->b_cap_prog = rp; /* restore the previous program */
6833 return e_invarg;
6834 }
6835 vim_free(re);
6836 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006837 }
6838
6839 vim_free(rp);
6840 return NULL;
6841}
6842#endif
6843
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006844#if defined(FEAT_EVAL) || defined(PROTO)
6845/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006846 * Set the scriptID for an option, taking care of setting the buffer- or
6847 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006848 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006849 static void
6850set_option_scriptID_idx(opt_idx, opt_flags, id)
6851 int opt_idx;
6852 int opt_flags;
6853 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006854{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006855 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
6856 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006857
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006858 /* Remember where the option was set. For local options need to do that
6859 * in the buffer or window structure. */
6860 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006861 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006862 if (both || (opt_flags & OPT_LOCAL))
6863 {
6864 if (indir & PV_BUF)
6865 curbuf->b_p_scriptID[indir & PV_MASK] = id;
6866 else if (indir & PV_WIN)
6867 curwin->w_p_scriptID[indir & PV_MASK] = id;
6868 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006869}
6870#endif
6871
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872/*
6873 * Set the value of a boolean option, and take care of side effects.
6874 * Returns NULL for success, or an error message for an error.
6875 */
6876 static char_u *
6877set_bool_option(opt_idx, varp, value, opt_flags)
6878 int opt_idx; /* index in options[] table */
6879 char_u *varp; /* pointer to the option variable */
6880 int value; /* new value */
6881 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6882{
6883 int old_value = *(int *)varp;
6884
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 /* Disallow changing some options from secure mode */
6886 if ((secure
6887#ifdef HAVE_SANDBOX
6888 || sandbox != 0
6889#endif
6890 ) && (options[opt_idx].flags & P_SECURE))
6891 return e_secure;
6892
6893 *(int *)varp = value; /* set the new value */
6894#ifdef FEAT_EVAL
6895 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006896 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006897#endif
6898
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006899#ifdef FEAT_GUI
6900 need_mouse_correct = TRUE;
6901#endif
6902
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 /* May set global value for local option. */
6904 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6905 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6906
6907 /*
6908 * Handle side effects of changing a bool option.
6909 */
6910
6911 /* 'compatible' */
6912 if ((int *)varp == &p_cp)
6913 {
6914 compatible_set();
6915 }
6916
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 else if ((int *)varp == &curbuf->b_p_ro)
6918 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006919 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6921 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006922
6923 /* when 'readonly' is set may give W10 again */
6924 if (curbuf->b_p_ro)
6925 curbuf->b_did_warn = FALSE;
6926
Bram Moolenaar071d4272004-06-13 20:20:40 +00006927#ifdef FEAT_TITLE
6928 need_maketitle = TRUE;
6929#endif
6930 }
6931
6932#ifdef FEAT_TITLE
6933 /* when 'modifiable' is changed, redraw the window title */
6934 else if ((int *)varp == &curbuf->b_p_ma)
6935 need_maketitle = TRUE;
6936 /* when 'endofline' is changed, redraw the window title */
6937 else if ((int *)varp == &curbuf->b_p_eol)
6938 need_maketitle = TRUE;
6939#endif
6940
6941 /* when 'bin' is set also set some other options */
6942 else if ((int *)varp == &curbuf->b_p_bin)
6943 {
6944 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6945#ifdef FEAT_TITLE
6946 need_maketitle = TRUE;
6947#endif
6948 }
6949
6950#ifdef FEAT_AUTOCMD
6951 /* when 'buflisted' changes, trigger autocommands */
6952 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6953 {
6954 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6955 NULL, NULL, TRUE, curbuf);
6956 }
6957#endif
6958
6959 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6960 else if ((int *)varp == &curbuf->b_p_swf)
6961 {
6962 if (curbuf->b_p_swf && p_uc)
6963 ml_open_file(curbuf); /* create the swap file */
6964 else
6965 mf_close_file(curbuf, TRUE); /* remove the swap file */
6966 }
6967
6968 /* when 'terse' is set change 'shortmess' */
6969 else if ((int *)varp == &p_terse)
6970 {
6971 char_u *p;
6972
6973 p = vim_strchr(p_shm, SHM_SEARCH);
6974
6975 /* insert 's' in p_shm */
6976 if (p_terse && p == NULL)
6977 {
6978 STRCPY(IObuff, p_shm);
6979 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006980 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981 }
6982 /* remove 's' from p_shm */
6983 else if (!p_terse && p != NULL)
6984 mch_memmove(p, p + 1, STRLEN(p));
6985 }
6986
6987 /* when 'paste' is set or reset also change other options */
6988 else if ((int *)varp == &p_paste)
6989 {
6990 paste_option_changed();
6991 }
6992
6993 /* when 'insertmode' is set from an autocommand need to do work here */
6994 else if ((int *)varp == &p_im)
6995 {
6996 if (p_im)
6997 {
6998 if ((State & INSERT) == 0)
6999 need_start_insertmode = TRUE;
7000 stop_insert_mode = FALSE;
7001 }
7002 else
7003 {
7004 need_start_insertmode = FALSE;
7005 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007006 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 clear_cmdline = TRUE; /* remove "(insert)" */
7008 restart_edit = 0;
7009 }
7010 }
7011
7012 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7013 else if ((int *)varp == &p_ic && p_hls)
7014 {
7015 redraw_all_later(NOT_VALID);
7016 }
7017
7018#ifdef FEAT_SEARCH_EXTRA
7019 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7020 else if ((int *)varp == &p_hls)
7021 {
7022 no_hlsearch = FALSE;
7023 }
7024#endif
7025
7026#ifdef FEAT_SCROLLBIND
7027 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7028 * at the end of normal_cmd() */
7029 else if ((int *)varp == &curwin->w_p_scb)
7030 {
7031 if (curwin->w_p_scb)
7032 do_check_scrollbind(FALSE);
7033 }
7034#endif
7035
7036#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7037 /* There can be only one window with 'previewwindow' set. */
7038 else if ((int *)varp == &curwin->w_p_pvw)
7039 {
7040 if (curwin->w_p_pvw)
7041 {
7042 win_T *win;
7043
7044 for (win = firstwin; win != NULL; win = win->w_next)
7045 if (win->w_p_pvw && win != curwin)
7046 {
7047 curwin->w_p_pvw = FALSE;
7048 return (char_u *)N_("E590: A preview window already exists");
7049 }
7050 }
7051 }
7052#endif
7053
7054 /* when 'textmode' is set or reset also change 'fileformat' */
7055 else if ((int *)varp == &curbuf->b_p_tx)
7056 {
7057 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7058 }
7059
7060 /* when 'textauto' is set or reset also change 'fileformats' */
7061 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062 set_string_option_direct((char_u *)"ffs", -1,
7063 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007064 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007065
7066 /*
7067 * When 'lisp' option changes include/exclude '-' in
7068 * keyword characters.
7069 */
7070#ifdef FEAT_LISP
7071 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7072 {
7073 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7074 }
7075#endif
7076
7077#ifdef FEAT_TITLE
7078 /* when 'title' changed, may need to change the title; same for 'icon' */
7079 else if ((int *)varp == &p_title)
7080 {
7081 did_set_title(FALSE);
7082 }
7083
7084 else if ((int *)varp == &p_icon)
7085 {
7086 did_set_title(TRUE);
7087 }
7088#endif
7089
7090 else if ((int *)varp == &curbuf->b_changed)
7091 {
7092 if (!value)
7093 save_file_ff(curbuf); /* Buffer is unchanged */
7094#ifdef FEAT_TITLE
7095 need_maketitle = TRUE;
7096#endif
7097#ifdef FEAT_AUTOCMD
7098 modified_was_set = value;
7099#endif
7100 }
7101
7102#ifdef BACKSLASH_IN_FILENAME
7103 else if ((int *)varp == &p_ssl)
7104 {
7105 if (p_ssl)
7106 {
7107 psepc = '/';
7108 psepcN = '\\';
7109 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 }
7111 else
7112 {
7113 psepc = '\\';
7114 psepcN = '/';
7115 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116 }
7117
7118 /* need to adjust the file name arguments and buffer names. */
7119 buflist_slash_adjust();
7120 alist_slash_adjust();
7121# ifdef FEAT_EVAL
7122 scriptnames_slash_adjust();
7123# endif
7124 }
7125#endif
7126
7127 /* If 'wrap' is set, set w_leftcol to zero. */
7128 else if ((int *)varp == &curwin->w_p_wrap)
7129 {
7130 if (curwin->w_p_wrap)
7131 curwin->w_leftcol = 0;
7132 }
7133
7134#ifdef FEAT_WINDOWS
7135 else if ((int *)varp == &p_ea)
7136 {
7137 if (p_ea && !old_value)
7138 win_equal(curwin, FALSE, 0);
7139 }
7140#endif
7141
7142 else if ((int *)varp == &p_wiv)
7143 {
7144 /*
7145 * When 'weirdinvert' changed, set/reset 't_xs'.
7146 * Then set 'weirdinvert' according to value of 't_xs'.
7147 */
7148 if (p_wiv && !old_value)
7149 T_XS = (char_u *)"y";
7150 else if (!p_wiv && old_value)
7151 T_XS = empty_option;
7152 p_wiv = (*T_XS != NUL);
7153 }
7154
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007155#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156 else if ((int *)varp == &p_beval)
7157 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 if (p_beval == TRUE)
7159 gui_mch_enable_beval_area(balloonEval);
7160 else
7161 gui_mch_disable_beval_area(balloonEval);
7162 }
7163
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007164# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 else if ((int *)varp == &p_acd)
7166 {
7167 if (p_acd && curbuf->b_ffname != NULL
7168 && vim_chdirfile(curbuf->b_ffname) == OK)
7169 shorten_fnames(TRUE);
7170 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007171# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172#endif
7173
7174#ifdef FEAT_DIFF
7175 /* 'diff' */
7176 else if ((int *)varp == &curwin->w_p_diff)
7177 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007178 /* May add or remove the buffer from the list of diff buffers. */
7179 diff_buf_adjust(curwin);
7180# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 if (foldmethodIsDiff(curwin))
7182 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007183# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 }
7185#endif
7186
7187#ifdef USE_IM_CONTROL
7188 /* 'imdisable' */
7189 else if ((int *)varp == &p_imdisable)
7190 {
7191 /* Only de-activate it here, it will be enabled when changing mode. */
7192 if (p_imdisable)
7193 im_set_active(FALSE);
7194 }
7195#endif
7196
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007197#ifdef FEAT_SYN_HL
7198 /* 'spell' */
7199 else if ((int *)varp == &curwin->w_p_spell)
7200 {
7201 if (curwin->w_p_spell)
7202 {
7203 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007204
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007205 if (errmsg != NULL)
7206 EMSG(_(errmsg));
7207 }
7208 }
7209#endif
7210
Bram Moolenaar071d4272004-06-13 20:20:40 +00007211#ifdef FEAT_FKMAP
7212 else if ((int *)varp == &p_altkeymap)
7213 {
7214 if (old_value != p_altkeymap)
7215 {
7216 if (!p_altkeymap)
7217 {
7218 p_hkmap = p_fkmap;
7219 p_fkmap = 0;
7220 }
7221 else
7222 {
7223 p_fkmap = p_hkmap;
7224 p_hkmap = 0;
7225 }
7226 (void)init_chartab();
7227 }
7228 }
7229
7230 /*
7231 * In case some second language keymapping options have changed, check
7232 * and correct the setting in a consistent way.
7233 */
7234
7235 /*
7236 * If hkmap or fkmap are set, reset Arabic keymapping.
7237 */
7238 if ((p_hkmap || p_fkmap) && p_altkeymap)
7239 {
7240 p_altkeymap = p_fkmap;
7241# ifdef FEAT_ARABIC
7242 curwin->w_p_arab = FALSE;
7243# endif
7244 (void)init_chartab();
7245 }
7246
7247 /*
7248 * If hkmap set, reset Farsi keymapping.
7249 */
7250 if (p_hkmap && p_altkeymap)
7251 {
7252 p_altkeymap = 0;
7253 p_fkmap = 0;
7254# ifdef FEAT_ARABIC
7255 curwin->w_p_arab = FALSE;
7256# endif
7257 (void)init_chartab();
7258 }
7259
7260 /*
7261 * If fkmap set, reset Hebrew keymapping.
7262 */
7263 if (p_fkmap && !p_altkeymap)
7264 {
7265 p_altkeymap = 1;
7266 p_hkmap = 0;
7267# ifdef FEAT_ARABIC
7268 curwin->w_p_arab = FALSE;
7269# endif
7270 (void)init_chartab();
7271 }
7272#endif
7273
7274#ifdef FEAT_ARABIC
7275 if ((int *)varp == &curwin->w_p_arab)
7276 {
7277 if (curwin->w_p_arab)
7278 {
7279 /*
7280 * 'arabic' is set, handle various sub-settings.
7281 */
7282 if (!p_tbidi)
7283 {
7284 /* set rightleft mode */
7285 if (!curwin->w_p_rl)
7286 {
7287 curwin->w_p_rl = TRUE;
7288 changed_window_setting();
7289 }
7290
7291 /* Enable Arabic shaping (major part of what Arabic requires) */
7292 if (!p_arshape)
7293 {
7294 p_arshape = TRUE;
7295 redraw_later_clear();
7296 }
7297 }
7298
7299 /* Arabic requires a utf-8 encoding, inform the user if its not
7300 * set. */
7301 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007302 {
7303 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007304 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7305 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307
7308# ifdef FEAT_MBYTE
7309 /* set 'delcombine' */
7310 p_deco = TRUE;
7311# endif
7312
7313# ifdef FEAT_KEYMAP
7314 /* Force-set the necessary keymap for arabic */
7315 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7316 OPT_LOCAL);
7317# endif
7318# ifdef FEAT_FKMAP
7319 p_altkeymap = 0;
7320 p_hkmap = 0;
7321 p_fkmap = 0;
7322 (void)init_chartab();
7323# endif
7324 }
7325 else
7326 {
7327 /*
7328 * 'arabic' is reset, handle various sub-settings.
7329 */
7330 if (!p_tbidi)
7331 {
7332 /* reset rightleft mode */
7333 if (curwin->w_p_rl)
7334 {
7335 curwin->w_p_rl = FALSE;
7336 changed_window_setting();
7337 }
7338
7339 /* 'arabicshape' isn't reset, it is a global option and
7340 * another window may still need it "on". */
7341 }
7342
7343 /* 'delcombine' isn't reset, it is a global option and another
7344 * window may still want it "on". */
7345
7346# ifdef FEAT_KEYMAP
7347 /* Revert to the default keymap */
7348 curbuf->b_p_iminsert = B_IMODE_NONE;
7349 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7350# endif
7351 }
7352 }
7353#endif
7354
7355 /*
7356 * End of handling side effects for bool options.
7357 */
7358
7359 options[opt_idx].flags |= P_WAS_SET;
7360
7361 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7362 if (curwin->w_curswant != MAXCOL)
7363 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7364 check_redraw(options[opt_idx].flags);
7365
7366 return NULL;
7367}
7368
7369/*
7370 * Set the value of a number option, and take care of side effects.
7371 * Returns NULL for success, or an error message for an error.
7372 */
7373 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007374set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375 int opt_idx; /* index in options[] table */
7376 char_u *varp; /* pointer to the option variable */
7377 long value; /* new value */
7378 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007379 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7381 OPT_MODELINE */
7382{
7383 char_u *errmsg = NULL;
7384 long old_value = *(long *)varp;
7385 long old_Rows = Rows; /* remember old Rows */
7386 long old_Columns = Columns; /* remember old Columns */
7387 long *pp = (long *)varp;
7388
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007389 /* Disallow changing some options from secure mode. */
7390 if ((secure
7391#ifdef HAVE_SANDBOX
7392 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007393#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007394 ) && (options[opt_idx].flags & P_SECURE))
7395 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396
7397 *pp = value;
7398#ifdef FEAT_EVAL
7399 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007400 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007401#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007402#ifdef FEAT_GUI
7403 need_mouse_correct = TRUE;
7404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007405
7406 if (curbuf->b_p_sw <= 0)
7407 {
7408 errmsg = e_positive;
7409 curbuf->b_p_sw = curbuf->b_p_ts;
7410 }
7411
7412 /*
7413 * Number options that need some action when changed
7414 */
7415#ifdef FEAT_WINDOWS
7416 if (pp == &p_wh || pp == &p_hh)
7417 {
7418 if (p_wh < 1)
7419 {
7420 errmsg = e_positive;
7421 p_wh = 1;
7422 }
7423 if (p_wmh > p_wh)
7424 {
7425 errmsg = e_winheight;
7426 p_wh = p_wmh;
7427 }
7428 if (p_hh < 0)
7429 {
7430 errmsg = e_positive;
7431 p_hh = 0;
7432 }
7433
7434 /* Change window height NOW */
7435 if (lastwin != firstwin)
7436 {
7437 if (pp == &p_wh && curwin->w_height < p_wh)
7438 win_setheight((int)p_wh);
7439 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7440 win_setheight((int)p_hh);
7441 }
7442 }
7443
7444 /* 'winminheight' */
7445 else if (pp == &p_wmh)
7446 {
7447 if (p_wmh < 0)
7448 {
7449 errmsg = e_positive;
7450 p_wmh = 0;
7451 }
7452 if (p_wmh > p_wh)
7453 {
7454 errmsg = e_winheight;
7455 p_wmh = p_wh;
7456 }
7457 win_setminheight();
7458 }
7459
7460# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007461 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 {
7463 if (p_wiw < 1)
7464 {
7465 errmsg = e_positive;
7466 p_wiw = 1;
7467 }
7468 if (p_wmw > p_wiw)
7469 {
7470 errmsg = e_winwidth;
7471 p_wiw = p_wmw;
7472 }
7473
7474 /* Change window width NOW */
7475 if (lastwin != firstwin && curwin->w_width < p_wiw)
7476 win_setwidth((int)p_wiw);
7477 }
7478
7479 /* 'winminwidth' */
7480 else if (pp == &p_wmw)
7481 {
7482 if (p_wmw < 0)
7483 {
7484 errmsg = e_positive;
7485 p_wmw = 0;
7486 }
7487 if (p_wmw > p_wiw)
7488 {
7489 errmsg = e_winwidth;
7490 p_wmw = p_wiw;
7491 }
7492 win_setminheight();
7493 }
7494# endif
7495
7496#endif
7497
7498#ifdef FEAT_WINDOWS
7499 /* (re)set last window status line */
7500 else if (pp == &p_ls)
7501 {
7502 last_status(FALSE);
7503 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007504
7505 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007506 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007507 {
7508 shell_new_rows(); /* recompute window positions and heights */
7509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510#endif
7511
7512#ifdef FEAT_GUI
7513 else if (pp == &p_linespace)
7514 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007515 /* Recompute gui.char_height and resize the Vim window to keep the
7516 * same number of lines. */
7517 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 gui_set_shellsize(FALSE, FALSE);
7519 }
7520#endif
7521
7522#ifdef FEAT_FOLDING
7523 /* 'foldlevel' */
7524 else if (pp == &curwin->w_p_fdl)
7525 {
7526 if (curwin->w_p_fdl < 0)
7527 curwin->w_p_fdl = 0;
7528 newFoldLevel();
7529 }
7530
7531 /* 'foldminlevel' */
7532 else if (pp == &curwin->w_p_fml)
7533 {
7534 foldUpdateAll(curwin);
7535 }
7536
7537 /* 'foldnestmax' */
7538 else if (pp == &curwin->w_p_fdn)
7539 {
7540 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7541 foldUpdateAll(curwin);
7542 }
7543
7544 /* 'foldcolumn' */
7545 else if (pp == &curwin->w_p_fdc)
7546 {
7547 if (curwin->w_p_fdc < 0)
7548 {
7549 errmsg = e_positive;
7550 curwin->w_p_fdc = 0;
7551 }
7552 else if (curwin->w_p_fdc > 12)
7553 {
7554 errmsg = e_invarg;
7555 curwin->w_p_fdc = 12;
7556 }
7557 }
7558
7559 /* 'shiftwidth' or 'tabstop' */
7560 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7561 {
7562 if (foldmethodIsIndent(curwin))
7563 foldUpdateAll(curwin);
7564 }
7565#endif /* FEAT_FOLDING */
7566
7567 else if (pp == &curbuf->b_p_iminsert)
7568 {
7569 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7570 {
7571 errmsg = e_invarg;
7572 curbuf->b_p_iminsert = B_IMODE_NONE;
7573 }
7574 p_iminsert = curbuf->b_p_iminsert;
7575 if (termcap_active) /* don't do this in the alternate screen */
7576 showmode();
7577#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7578 /* Show/unshow value of 'keymap' in status lines. */
7579 status_redraw_curbuf();
7580#endif
7581 }
7582
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007583 else if (pp == &p_window)
7584 {
7585 if (p_window < 1)
7586 p_window = 1;
7587 else if (p_window >= Rows)
7588 p_window = Rows - 1;
7589 }
7590
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591 else if (pp == &curbuf->b_p_imsearch)
7592 {
7593 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7594 {
7595 errmsg = e_invarg;
7596 curbuf->b_p_imsearch = B_IMODE_NONE;
7597 }
7598 p_imsearch = curbuf->b_p_imsearch;
7599 }
7600
7601#ifdef FEAT_TITLE
7602 /* if 'titlelen' has changed, redraw the title */
7603 else if (pp == &p_titlelen)
7604 {
7605 if (p_titlelen < 0)
7606 {
7607 errmsg = e_positive;
7608 p_titlelen = 85;
7609 }
7610 if (starting != NO_SCREEN && old_value != p_titlelen)
7611 need_maketitle = TRUE;
7612 }
7613#endif
7614
7615 /* if p_ch changed value, change the command line height */
7616 else if (pp == &p_ch)
7617 {
7618 if (p_ch < 1)
7619 {
7620 errmsg = e_positive;
7621 p_ch = 1;
7622 }
7623
7624 /* Only compute the new window layout when startup has been
7625 * completed. Otherwise the frame sizes may be wrong. */
7626 if (p_ch != old_value && full_screen
7627#ifdef FEAT_GUI
7628 && !gui.starting
7629#endif
7630 )
7631 command_height(old_value);
7632 }
7633
7634 /* when 'updatecount' changes from zero to non-zero, open swap files */
7635 else if (pp == &p_uc)
7636 {
7637 if (p_uc < 0)
7638 {
7639 errmsg = e_positive;
7640 p_uc = 100;
7641 }
7642 if (p_uc && !old_value)
7643 ml_open_files();
7644 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007645#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007646 else if (pp == &p_mzq)
7647 mzvim_reset_timer();
7648#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007649
7650 /* sync undo before 'undolevels' changes */
7651 else if (pp == &p_ul)
7652 {
7653 /* use the old value, otherwise u_sync() may not work properly */
7654 p_ul = old_value;
7655 u_sync();
7656 p_ul = value;
7657 }
7658
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007659#ifdef FEAT_LINEBREAK
7660 /* 'numberwidth' must be positive */
7661 else if (pp == &curwin->w_p_nuw)
7662 {
7663 if (curwin->w_p_nuw < 1)
7664 {
7665 errmsg = e_positive;
7666 curwin->w_p_nuw = 1;
7667 }
7668 if (curwin->w_p_nuw > 10)
7669 {
7670 errmsg = e_invarg;
7671 curwin->w_p_nuw = 10;
7672 }
7673 curwin->w_nrwidth_line_count = 0;
7674 }
7675#endif
7676
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677 /*
7678 * Check the bounds for numeric options here
7679 */
7680 if (Rows < min_rows() && full_screen)
7681 {
7682 if (errbuf != NULL)
7683 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007684 vim_snprintf((char *)errbuf, errbuflen,
7685 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 errmsg = errbuf;
7687 }
7688 Rows = min_rows();
7689 }
7690 if (Columns < MIN_COLUMNS && full_screen)
7691 {
7692 if (errbuf != NULL)
7693 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007694 vim_snprintf((char *)errbuf, errbuflen,
7695 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696 errmsg = errbuf;
7697 }
7698 Columns = MIN_COLUMNS;
7699 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007700 /* Limit the values to avoid an overflow in Rows * Columns. */
7701 if (Columns > 10000)
7702 Columns = 10000;
7703 if (Rows > 1000)
7704 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705
7706#ifdef DJGPP
7707 /* avoid a crash by checking for a too large value of 'columns' */
7708 if (old_Columns != Columns && full_screen && term_console)
7709 mch_check_columns();
7710#endif
7711
7712 /*
7713 * If the screen (shell) height has been changed, assume it is the
7714 * physical screenheight.
7715 */
7716 if (old_Rows != Rows || old_Columns != Columns)
7717 {
7718 /* Changing the screen size is not allowed while updating the screen. */
7719 if (updating_screen)
7720 *pp = old_value;
7721 else if (full_screen
7722#ifdef FEAT_GUI
7723 && !gui.starting
7724#endif
7725 )
7726 set_shellsize((int)Columns, (int)Rows, TRUE);
7727 else
7728 {
7729 /* Postpone the resizing; check the size and cmdline position for
7730 * messages. */
7731 check_shellsize();
7732 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7733 cmdline_row = Rows - p_ch;
7734 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007735 if (p_window >= Rows)
7736 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737 }
7738
7739 if (curbuf->b_p_sts < 0)
7740 {
7741 errmsg = e_positive;
7742 curbuf->b_p_sts = 0;
7743 }
7744 if (curbuf->b_p_ts <= 0)
7745 {
7746 errmsg = e_positive;
7747 curbuf->b_p_ts = 8;
7748 }
7749 if (curbuf->b_p_tw < 0)
7750 {
7751 errmsg = e_positive;
7752 curbuf->b_p_tw = 0;
7753 }
7754 if (p_tm < 0)
7755 {
7756 errmsg = e_positive;
7757 p_tm = 0;
7758 }
7759 if ((curwin->w_p_scr <= 0
7760 || (curwin->w_p_scr > curwin->w_height
7761 && curwin->w_height > 0))
7762 && full_screen)
7763 {
7764 if (pp == &(curwin->w_p_scr))
7765 {
7766 if (curwin->w_p_scr != 0)
7767 errmsg = e_scroll;
7768 win_comp_scroll(curwin);
7769 }
7770 /* If 'scroll' became invalid because of a side effect silently adjust
7771 * it. */
7772 else if (curwin->w_p_scr <= 0)
7773 curwin->w_p_scr = 1;
7774 else /* curwin->w_p_scr > curwin->w_height */
7775 curwin->w_p_scr = curwin->w_height;
7776 }
7777 if (p_report < 0)
7778 {
7779 errmsg = e_positive;
7780 p_report = 1;
7781 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007782 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 {
7784 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7785 p_sj = Rows / 2;
7786 else
7787 {
7788 errmsg = e_scroll;
7789 p_sj = 1;
7790 }
7791 }
7792 if (p_so < 0 && full_screen)
7793 {
7794 errmsg = e_scroll;
7795 p_so = 0;
7796 }
7797 if (p_siso < 0 && full_screen)
7798 {
7799 errmsg = e_positive;
7800 p_siso = 0;
7801 }
7802#ifdef FEAT_CMDWIN
7803 if (p_cwh < 1)
7804 {
7805 errmsg = e_positive;
7806 p_cwh = 1;
7807 }
7808#endif
7809 if (p_ut < 0)
7810 {
7811 errmsg = e_positive;
7812 p_ut = 2000;
7813 }
7814 if (p_ss < 0)
7815 {
7816 errmsg = e_positive;
7817 p_ss = 0;
7818 }
7819
7820 /* May set global value for local option. */
7821 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7822 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7823
7824 options[opt_idx].flags |= P_WAS_SET;
7825
7826 comp_col(); /* in case 'columns' or 'ls' changed */
7827 if (curwin->w_curswant != MAXCOL)
7828 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7829 check_redraw(options[opt_idx].flags);
7830
7831 return errmsg;
7832}
7833
7834/*
7835 * Called after an option changed: check if something needs to be redrawn.
7836 */
7837 static void
7838check_redraw(flags)
7839 long_u flags;
7840{
7841 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7842 int clear = (flags & P_RCLR) == P_RCLR;
7843 int all = ((flags & P_RALL) == P_RALL || clear);
7844
7845#ifdef FEAT_WINDOWS
7846 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7847 status_redraw_all();
7848#endif
7849
7850 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7851 changed_window_setting();
7852 if (flags & P_RBUF)
7853 redraw_curbuf_later(NOT_VALID);
7854 if (clear)
7855 redraw_all_later(CLEAR);
7856 else if (all)
7857 redraw_all_later(NOT_VALID);
7858}
7859
7860/*
7861 * Find index for option 'arg'.
7862 * Return -1 if not found.
7863 */
7864 static int
7865findoption(arg)
7866 char_u *arg;
7867{
7868 int opt_idx;
7869 char *s, *p;
7870 static short quick_tab[27] = {0, 0}; /* quick access table */
7871 int is_term_opt;
7872
7873 /*
7874 * For first call: Initialize the quick-access table.
7875 * It contains the index for the first option that starts with a certain
7876 * letter. There are 26 letters, plus the first "t_" option.
7877 */
7878 if (quick_tab[1] == 0)
7879 {
7880 p = options[0].fullname;
7881 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7882 {
7883 if (s[0] != p[0])
7884 {
7885 if (s[0] == 't' && s[1] == '_')
7886 quick_tab[26] = opt_idx;
7887 else
7888 quick_tab[CharOrdLow(s[0])] = opt_idx;
7889 }
7890 p = s;
7891 }
7892 }
7893
7894 /*
7895 * Check for name starting with an illegal character.
7896 */
7897#ifdef EBCDIC
7898 if (!islower(arg[0]))
7899#else
7900 if (arg[0] < 'a' || arg[0] > 'z')
7901#endif
7902 return -1;
7903
7904 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7905 if (is_term_opt)
7906 opt_idx = quick_tab[26];
7907 else
7908 opt_idx = quick_tab[CharOrdLow(arg[0])];
7909 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7910 {
7911 if (STRCMP(arg, s) == 0) /* match full name */
7912 break;
7913 }
7914 if (s == NULL && !is_term_opt)
7915 {
7916 opt_idx = quick_tab[CharOrdLow(arg[0])];
7917 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7918 {
7919 s = options[opt_idx].shortname;
7920 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7921 break;
7922 s = NULL;
7923 }
7924 }
7925 if (s == NULL)
7926 opt_idx = -1;
7927 return opt_idx;
7928}
7929
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007930#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931/*
7932 * Get the value for an option.
7933 *
7934 * Returns:
7935 * Number or Toggle option: 1, *numval gets value.
7936 * String option: 0, *stringval gets allocated string.
7937 * Hidden Number or Toggle option: -1.
7938 * hidden String option: -2.
7939 * unknown option: -3.
7940 */
7941 int
7942get_option_value(name, numval, stringval, opt_flags)
7943 char_u *name;
7944 long *numval;
7945 char_u **stringval; /* NULL when only checking existance */
7946 int opt_flags;
7947{
7948 int opt_idx;
7949 char_u *varp;
7950
7951 opt_idx = findoption(name);
7952 if (opt_idx < 0) /* unknown option */
7953 return -3;
7954
7955 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7956
7957 if (options[opt_idx].flags & P_STRING)
7958 {
7959 if (varp == NULL) /* hidden option */
7960 return -2;
7961 if (stringval != NULL)
7962 {
7963#ifdef FEAT_CRYPT
7964 /* never return the value of the crypt key */
7965 if ((char_u **)varp == &curbuf->b_p_key)
7966 *stringval = vim_strsave((char_u *)"*****");
7967 else
7968#endif
7969 *stringval = vim_strsave(*(char_u **)(varp));
7970 }
7971 return 0;
7972 }
7973
7974 if (varp == NULL) /* hidden option */
7975 return -1;
7976 if (options[opt_idx].flags & P_NUM)
7977 *numval = *(long *)varp;
7978 else
7979 {
7980 /* Special case: 'modified' is b_changed, but we also want to consider
7981 * it set when 'ff' or 'fenc' changed. */
7982 if ((int *)varp == &curbuf->b_changed)
7983 *numval = curbufIsChanged();
7984 else
7985 *numval = *(int *)varp;
7986 }
7987 return 1;
7988}
7989#endif
7990
7991/*
7992 * Set the value of option "name".
7993 * Use "string" for string options, use "number" for other options.
7994 */
7995 void
7996set_option_value(name, number, string, opt_flags)
7997 char_u *name;
7998 long number;
7999 char_u *string;
8000 int opt_flags; /* OPT_LOCAL or 0 (both) */
8001{
8002 int opt_idx;
8003 char_u *varp;
8004 int flags;
8005
8006 opt_idx = findoption(name);
8007 if (opt_idx == -1)
8008 EMSG2(_("E355: Unknown option: %s"), name);
8009 else
8010 {
8011 flags = options[opt_idx].flags;
8012#ifdef HAVE_SANDBOX
8013 /* Disallow changing some options in the sandbox */
8014 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008015 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008017 return;
8018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008019#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008020 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 set_string_option(opt_idx, string, opt_flags);
8022 else
8023 {
8024 varp = get_varp(&options[opt_idx]);
8025 if (varp != NULL) /* hidden option is not changed */
8026 {
8027 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008028 (void)set_num_option(opt_idx, varp, number,
8029 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008031 (void)set_bool_option(opt_idx, varp, (int)number,
8032 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033 }
8034 }
8035 }
8036}
8037
8038/*
8039 * Get the terminal code for a terminal option.
8040 * Returns NULL when not found.
8041 */
8042 char_u *
8043get_term_code(tname)
8044 char_u *tname;
8045{
8046 int opt_idx;
8047 char_u *varp;
8048
8049 if (tname[0] != 't' || tname[1] != '_' ||
8050 tname[2] == NUL || tname[3] == NUL)
8051 return NULL;
8052 if ((opt_idx = findoption(tname)) >= 0)
8053 {
8054 varp = get_varp(&(options[opt_idx]));
8055 if (varp != NULL)
8056 varp = *(char_u **)(varp);
8057 return varp;
8058 }
8059 return find_termcode(tname + 2);
8060}
8061
8062 char_u *
8063get_highlight_default()
8064{
8065 int i;
8066
8067 i = findoption((char_u *)"hl");
8068 if (i >= 0)
8069 return options[i].def_val[VI_DEFAULT];
8070 return (char_u *)NULL;
8071}
8072
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008073#if defined(FEAT_MBYTE) || defined(PROTO)
8074 char_u *
8075get_encoding_default()
8076{
8077 int i;
8078
8079 i = findoption((char_u *)"enc");
8080 if (i >= 0)
8081 return options[i].def_val[VI_DEFAULT];
8082 return (char_u *)NULL;
8083}
8084#endif
8085
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086/*
8087 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8088 */
8089 static int
8090find_key_option(arg)
8091 char_u *arg;
8092{
8093 int key;
8094 int modifiers;
8095
8096 /*
8097 * Don't use get_special_key_code() for t_xx, we don't want it to call
8098 * add_termcap_entry().
8099 */
8100 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8101 key = TERMCAP2KEY(arg[2], arg[3]);
8102 else
8103 {
8104 --arg; /* put arg at the '<' */
8105 modifiers = 0;
8106 key = find_special_key(&arg, &modifiers, TRUE);
8107 if (modifiers) /* can't handle modifiers here */
8108 key = 0;
8109 }
8110 return key;
8111}
8112
8113/*
8114 * if 'all' == 0: show changed options
8115 * if 'all' == 1: show all normal options
8116 * if 'all' == 2: show all terminal options
8117 */
8118 static void
8119showoptions(all, opt_flags)
8120 int all;
8121 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8122{
8123 struct vimoption *p;
8124 int col;
8125 int isterm;
8126 char_u *varp;
8127 struct vimoption **items;
8128 int item_count;
8129 int run;
8130 int row, rows;
8131 int cols;
8132 int i;
8133 int len;
8134
8135#define INC 20
8136#define GAP 3
8137
8138 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8139 PARAM_COUNT));
8140 if (items == NULL)
8141 return;
8142
8143 /* Highlight title */
8144 if (all == 2)
8145 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8146 else if (opt_flags & OPT_GLOBAL)
8147 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8148 else if (opt_flags & OPT_LOCAL)
8149 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8150 else
8151 MSG_PUTS_TITLE(_("\n--- Options ---"));
8152
8153 /*
8154 * do the loop two times:
8155 * 1. display the short items
8156 * 2. display the long items (only strings and numbers)
8157 */
8158 for (run = 1; run <= 2 && !got_int; ++run)
8159 {
8160 /*
8161 * collect the items in items[]
8162 */
8163 item_count = 0;
8164 for (p = &options[0]; p->fullname != NULL; p++)
8165 {
8166 varp = NULL;
8167 isterm = istermoption(p);
8168 if (opt_flags != 0)
8169 {
8170 if (p->indir != PV_NONE && !isterm)
8171 varp = get_varp_scope(p, opt_flags);
8172 }
8173 else
8174 varp = get_varp(p);
8175 if (varp != NULL
8176 && ((all == 2 && isterm)
8177 || (all == 1 && !isterm)
8178 || (all == 0 && !optval_default(p, varp))))
8179 {
8180 if (p->flags & P_BOOL)
8181 len = 1; /* a toggle option fits always */
8182 else
8183 {
8184 option_value2string(p, opt_flags);
8185 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8186 }
8187 if ((len <= INC - GAP && run == 1) ||
8188 (len > INC - GAP && run == 2))
8189 items[item_count++] = p;
8190 }
8191 }
8192
8193 /*
8194 * display the items
8195 */
8196 if (run == 1)
8197 {
8198 cols = (Columns + GAP - 3) / INC;
8199 if (cols == 0)
8200 cols = 1;
8201 rows = (item_count + cols - 1) / cols;
8202 }
8203 else /* run == 2 */
8204 rows = item_count;
8205 for (row = 0; row < rows && !got_int; ++row)
8206 {
8207 msg_putchar('\n'); /* go to next line */
8208 if (got_int) /* 'q' typed in more */
8209 break;
8210 col = 0;
8211 for (i = row; i < item_count; i += rows)
8212 {
8213 msg_col = col; /* make columns */
8214 showoneopt(items[i], opt_flags);
8215 col += INC;
8216 }
8217 out_flush();
8218 ui_breakcheck();
8219 }
8220 }
8221 vim_free(items);
8222}
8223
8224/*
8225 * Return TRUE if option "p" has its default value.
8226 */
8227 static int
8228optval_default(p, varp)
8229 struct vimoption *p;
8230 char_u *varp;
8231{
8232 int dvi;
8233
8234 if (varp == NULL)
8235 return TRUE; /* hidden option is always at default */
8236 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8237 if (p->flags & P_NUM)
8238 return (*(long *)varp == (long)p->def_val[dvi]);
8239 if (p->flags & P_BOOL)
8240 /* the cast to long is required for Manx C */
8241 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8242 /* P_STRING */
8243 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8244}
8245
8246/*
8247 * showoneopt: show the value of one option
8248 * must not be called with a hidden option!
8249 */
8250 static void
8251showoneopt(p, opt_flags)
8252 struct vimoption *p;
8253 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8254{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008255 char_u *varp;
8256 int save_silent = silent_mode;
8257
8258 silent_mode = FALSE;
8259 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260
8261 varp = get_varp_scope(p, opt_flags);
8262
8263 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8264 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8265 ? !curbufIsChanged() : !*(int *)varp))
8266 MSG_PUTS("no");
8267 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8268 MSG_PUTS("--");
8269 else
8270 MSG_PUTS(" ");
8271 MSG_PUTS(p->fullname);
8272 if (!(p->flags & P_BOOL))
8273 {
8274 msg_putchar('=');
8275 /* put value string in NameBuff */
8276 option_value2string(p, opt_flags);
8277 msg_outtrans(NameBuff);
8278 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008279
8280 silent_mode = save_silent;
8281 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282}
8283
8284/*
8285 * Write modified options as ":set" commands to a file.
8286 *
8287 * There are three values for "opt_flags":
8288 * OPT_GLOBAL: Write global option values and fresh values of
8289 * buffer-local options (used for start of a session
8290 * file).
8291 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8292 * curwin (used for a vimrc file).
8293 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8294 * and local values for window-local options of
8295 * curwin. Local values are also written when at the
8296 * default value, because a modeline or autocommand
8297 * may have set them when doing ":edit file" and the
8298 * user has set them back at the default or fresh
8299 * value.
8300 * When "local_only" is TRUE, don't write fresh
8301 * values, only local values (for ":mkview").
8302 * (fresh value = value used for a new buffer or window for a local option).
8303 *
8304 * Return FAIL on error, OK otherwise.
8305 */
8306 int
8307makeset(fd, opt_flags, local_only)
8308 FILE *fd;
8309 int opt_flags;
8310 int local_only;
8311{
8312 struct vimoption *p;
8313 char_u *varp; /* currently used value */
8314 char_u *varp_fresh; /* local value */
8315 char_u *varp_local = NULL; /* fresh value */
8316 char *cmd;
8317 int round;
8318
8319 /*
8320 * The options that don't have a default (terminal name, columns, lines)
8321 * are never written. Terminal options are also not written.
8322 */
8323 for (p = &options[0]; !istermoption(p); p++)
8324 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8325 {
8326 /* skip global option when only doing locals */
8327 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8328 continue;
8329
8330 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8331 * file, they are always buffer-specific. */
8332 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8333 continue;
8334
8335 /* Global values are only written when not at the default value. */
8336 varp = get_varp_scope(p, opt_flags);
8337 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8338 continue;
8339
8340 round = 2;
8341 if (p->indir != PV_NONE)
8342 {
8343 if (p->var == VAR_WIN)
8344 {
8345 /* skip window-local option when only doing globals */
8346 if (!(opt_flags & OPT_LOCAL))
8347 continue;
8348 /* When fresh value of window-local option is not at the
8349 * default, need to write it too. */
8350 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8351 {
8352 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8353 if (!optval_default(p, varp_fresh))
8354 {
8355 round = 1;
8356 varp_local = varp;
8357 varp = varp_fresh;
8358 }
8359 }
8360 }
8361 }
8362
8363 /* Round 1: fresh value for window-local options.
8364 * Round 2: other values */
8365 for ( ; round <= 2; varp = varp_local, ++round)
8366 {
8367 if (round == 1 || (opt_flags & OPT_GLOBAL))
8368 cmd = "set";
8369 else
8370 cmd = "setlocal";
8371
8372 if (p->flags & P_BOOL)
8373 {
8374 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8375 return FAIL;
8376 }
8377 else if (p->flags & P_NUM)
8378 {
8379 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8380 return FAIL;
8381 }
8382 else /* P_STRING */
8383 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008384#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8385 int do_endif = FALSE;
8386
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 /* Don't set 'syntax' and 'filetype' again if the value is
8388 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008389 if (
8390# if defined(FEAT_SYN_HL)
8391 p->indir == PV_SYN
8392# if defined(FEAT_AUTOCMD)
8393 ||
8394# endif
8395# endif
8396# if defined(FEAT_AUTOCMD)
8397 p->indir == PV_FT)
8398# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008399 {
8400 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8401 *(char_u **)(varp)) < 0
8402 || put_eol(fd) < 0)
8403 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008404 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8408 (p->flags & P_EXPAND) != 0) == FAIL)
8409 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008410#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8411 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 {
8413 if (put_line(fd, "endif") == FAIL)
8414 return FAIL;
8415 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 }
8418 }
8419 }
8420 return OK;
8421}
8422
8423#if defined(FEAT_FOLDING) || defined(PROTO)
8424/*
8425 * Generate set commands for the local fold options only. Used when
8426 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8427 */
8428 int
8429makefoldset(fd)
8430 FILE *fd;
8431{
8432 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8433# ifdef FEAT_EVAL
8434 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8435 == FAIL
8436# endif
8437 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8438 == FAIL
8439 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8440 == FAIL
8441 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8442 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8443 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8444 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8445 )
8446 return FAIL;
8447
8448 return OK;
8449}
8450#endif
8451
8452 static int
8453put_setstring(fd, cmd, name, valuep, expand)
8454 FILE *fd;
8455 char *cmd;
8456 char *name;
8457 char_u **valuep;
8458 int expand;
8459{
8460 char_u *s;
8461 char_u buf[MAXPATHL];
8462
8463 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8464 return FAIL;
8465 if (*valuep != NULL)
8466 {
8467 /* Output 'pastetoggle' as key names. For other
8468 * options some characters have to be escaped with
8469 * CTRL-V or backslash */
8470 if (valuep == &p_pt)
8471 {
8472 s = *valuep;
8473 while (*s != NUL)
8474 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8475 return FAIL;
8476 }
8477 else if (expand)
8478 {
8479 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8480 if (put_escstr(fd, buf, 2) == FAIL)
8481 return FAIL;
8482 }
8483 else if (put_escstr(fd, *valuep, 2) == FAIL)
8484 return FAIL;
8485 }
8486 if (put_eol(fd) < 0)
8487 return FAIL;
8488 return OK;
8489}
8490
8491 static int
8492put_setnum(fd, cmd, name, valuep)
8493 FILE *fd;
8494 char *cmd;
8495 char *name;
8496 long *valuep;
8497{
8498 long wc;
8499
8500 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8501 return FAIL;
8502 if (wc_use_keyname((char_u *)valuep, &wc))
8503 {
8504 /* print 'wildchar' and 'wildcharm' as a key name */
8505 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8506 return FAIL;
8507 }
8508 else if (fprintf(fd, "%ld", *valuep) < 0)
8509 return FAIL;
8510 if (put_eol(fd) < 0)
8511 return FAIL;
8512 return OK;
8513}
8514
8515 static int
8516put_setbool(fd, cmd, name, value)
8517 FILE *fd;
8518 char *cmd;
8519 char *name;
8520 int value;
8521{
8522 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8523 || put_eol(fd) < 0)
8524 return FAIL;
8525 return OK;
8526}
8527
8528/*
8529 * Clear all the terminal options.
8530 * If the option has been allocated, free the memory.
8531 * Terminal options are never hidden or indirect.
8532 */
8533 void
8534clear_termoptions()
8535{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536 /*
8537 * Reset a few things before clearing the old options. This may cause
8538 * outputting a few things that the terminal doesn't understand, but the
8539 * screen will be cleared later, so this is OK.
8540 */
8541#ifdef FEAT_MOUSE_TTY
8542 mch_setmouse(FALSE); /* switch mouse off */
8543#endif
8544#ifdef FEAT_TITLE
8545 mch_restore_title(3); /* restore window titles */
8546#endif
8547#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8548 /* When starting the GUI close the display opened for the clipboard.
8549 * After restoring the title, because that will need the display. */
8550 if (gui.starting)
8551 clear_xterm_clip();
8552#endif
8553#ifdef WIN3264
8554 /*
8555 * Check if this is allowed now.
8556 */
8557 if (can_end_termcap_mode(FALSE) == TRUE)
8558#endif
8559 stoptermcap(); /* stop termcap mode */
8560
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008561 free_termoptions();
8562}
8563
8564 void
8565free_termoptions()
8566{
8567 struct vimoption *p;
8568
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 for (p = &options[0]; p->fullname != NULL; p++)
8570 if (istermoption(p))
8571 {
8572 if (p->flags & P_ALLOCED)
8573 free_string_option(*(char_u **)(p->var));
8574 if (p->flags & P_DEF_ALLOCED)
8575 free_string_option(p->def_val[VI_DEFAULT]);
8576 *(char_u **)(p->var) = empty_option;
8577 p->def_val[VI_DEFAULT] = empty_option;
8578 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8579 }
8580 clear_termcodes();
8581}
8582
8583/*
8584 * Set the terminal option defaults to the current value.
8585 * Used after setting the terminal name.
8586 */
8587 void
8588set_term_defaults()
8589{
8590 struct vimoption *p;
8591
8592 for (p = &options[0]; p->fullname != NULL; p++)
8593 {
8594 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8595 {
8596 if (p->flags & P_DEF_ALLOCED)
8597 {
8598 free_string_option(p->def_val[VI_DEFAULT]);
8599 p->flags &= ~P_DEF_ALLOCED;
8600 }
8601 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8602 if (p->flags & P_ALLOCED)
8603 {
8604 p->flags |= P_DEF_ALLOCED;
8605 p->flags &= ~P_ALLOCED; /* don't free the value now */
8606 }
8607 }
8608 }
8609}
8610
8611/*
8612 * return TRUE if 'p' starts with 't_'
8613 */
8614 static int
8615istermoption(p)
8616 struct vimoption *p;
8617{
8618 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8619}
8620
8621/*
8622 * Compute columns for ruler and shown command. 'sc_col' is also used to
8623 * decide what the maximum length of a message on the status line can be.
8624 * If there is a status line for the last window, 'sc_col' is independent
8625 * of 'ru_col'.
8626 */
8627
8628#define COL_RULER 17 /* columns needed by standard ruler */
8629
8630 void
8631comp_col()
8632{
8633#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8634 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8635
8636 sc_col = 0;
8637 ru_col = 0;
8638 if (p_ru)
8639 {
8640#ifdef FEAT_STL_OPT
8641 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8642#else
8643 ru_col = COL_RULER + 1;
8644#endif
8645 /* no last status line, adjust sc_col */
8646 if (!last_has_status)
8647 sc_col = ru_col;
8648 }
8649 if (p_sc)
8650 {
8651 sc_col += SHOWCMD_COLS;
8652 if (!p_ru || last_has_status) /* no need for separating space */
8653 ++sc_col;
8654 }
8655 sc_col = Columns - sc_col;
8656 ru_col = Columns - ru_col;
8657 if (sc_col <= 0) /* screen too narrow, will become a mess */
8658 sc_col = 1;
8659 if (ru_col <= 0)
8660 ru_col = 1;
8661#else
8662 sc_col = Columns;
8663 ru_col = Columns;
8664#endif
8665}
8666
8667/*
8668 * Get pointer to option variable, depending on local or global scope.
8669 */
8670 static char_u *
8671get_varp_scope(p, opt_flags)
8672 struct vimoption *p;
8673 int opt_flags;
8674{
8675 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8676 {
8677 if (p->var == VAR_WIN)
8678 return (char_u *)GLOBAL_WO(get_varp(p));
8679 return p->var;
8680 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008681 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 {
8683 switch ((int)p->indir)
8684 {
8685#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008686 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
8687 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
8688 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008690 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
8691 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
8692 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008693 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008694 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008696 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
8697 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698#endif
8699#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008700 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
8701 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008702#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008703#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008704 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706 }
8707 return NULL; /* "cannot happen" */
8708 }
8709 return get_varp(p);
8710}
8711
8712/*
8713 * Get pointer to option variable.
8714 */
8715 static char_u *
8716get_varp(p)
8717 struct vimoption *p;
8718{
8719 /* hidden option, always return NULL */
8720 if (p->var == NULL)
8721 return NULL;
8722
8723 switch ((int)p->indir)
8724 {
8725 case PV_NONE: return p->var;
8726
8727 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008728 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008730 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008732 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00008734 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008736 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8738#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008739 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008741 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8743#endif
8744#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008745 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008747 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8749#endif
8750#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008751 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008753 case PV_GP: return *curbuf->b_p_gp != NUL
8754 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8755 case PV_MP: return *curbuf->b_p_mp != NUL
8756 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008758#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008759 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008760 ? (char_u *)&(curwin->w_p_stl) : p->var;
8761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762
8763#ifdef FEAT_ARABIC
8764 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8765#endif
8766 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008767#ifdef FEAT_SYN_HL
8768 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008770#ifdef FEAT_DIFF
8771 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8772#endif
8773#ifdef FEAT_FOLDING
8774 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8775 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8776 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8777 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8778 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8779 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8780 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8781# ifdef FEAT_EVAL
8782 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8783 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8784# endif
8785 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8786#endif
8787 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008788#ifdef FEAT_LINEBREAK
8789 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8790#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008791#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00008792 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8793#endif
8794#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8795 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8796#endif
8797#ifdef FEAT_RIGHTLEFT
8798 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8799 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8800#endif
8801 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8802 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8803#ifdef FEAT_LINEBREAK
8804 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8805#endif
8806#ifdef FEAT_SCROLLBIND
8807 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8808#endif
8809
8810 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8811 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8812#ifdef FEAT_MBYTE
8813 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8814#endif
8815#if defined(FEAT_QUICKFIX)
8816 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8817 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8818#endif
8819 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8820 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8821#ifdef FEAT_CINDENT
8822 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8823 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8824 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8825#endif
8826#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8827 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8828#endif
8829#ifdef FEAT_COMMENTS
8830 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8831#endif
8832#ifdef FEAT_FOLDING
8833 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8834#endif
8835#ifdef FEAT_INS_EXPAND
8836 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8837#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008838#ifdef FEAT_COMPL_FUNC
8839 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008840 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8843 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8844#ifdef FEAT_MBYTE
8845 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8846#endif
8847 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8848#ifdef FEAT_AUTOCMD
8849 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8850#endif
8851 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008852 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8854 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8855 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8856 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8857#ifdef FEAT_FIND_ID
8858# ifdef FEAT_EVAL
8859 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8860# endif
8861#endif
8862#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8863 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8864 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8865#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008866#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008867 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869#ifdef FEAT_CRYPT
8870 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8871#endif
8872#ifdef FEAT_LISP
8873 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8874#endif
8875 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8876 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8877 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8878 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8879 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8880#ifdef FEAT_OSFILETYPE
8881 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8882#endif
8883 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008884#ifdef FEAT_TEXTOBJ
8885 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8886#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008887 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8888#ifdef FEAT_SMARTINDENT
8889 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8890#endif
8891#ifndef SHORT_FNAME
8892 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8893#endif
8894 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8895#ifdef FEAT_SEARCHPATH
8896 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8897#endif
8898 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8899#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008900 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008901 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008902 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008903 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008904 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905#endif
8906 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8907 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8908 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8909 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8910 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8911#ifdef FEAT_KEYMAP
8912 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8913#endif
8914 default: EMSG(_("E356: get_varp ERROR"));
8915 }
8916 /* always return a valid pointer to avoid a crash! */
8917 return (char_u *)&(curbuf->b_p_wm);
8918}
8919
8920/*
8921 * Get the value of 'equalprg', either the buffer-local one or the global one.
8922 */
8923 char_u *
8924get_equalprg()
8925{
8926 if (*curbuf->b_p_ep == NUL)
8927 return p_ep;
8928 return curbuf->b_p_ep;
8929}
8930
8931#if defined(FEAT_WINDOWS) || defined(PROTO)
8932/*
8933 * Copy options from one window to another.
8934 * Used when splitting a window.
8935 */
8936 void
8937win_copy_options(wp_from, wp_to)
8938 win_T *wp_from;
8939 win_T *wp_to;
8940{
8941 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8942 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8943# ifdef FEAT_RIGHTLEFT
8944# ifdef FEAT_FKMAP
8945 /* Is this right? */
8946 wp_to->w_farsi = wp_from->w_farsi;
8947# endif
8948# endif
8949}
8950#endif
8951
8952/*
8953 * Copy the options from one winopt_T to another.
8954 * Doesn't free the old option values in "to", use clear_winopt() for that.
8955 * The 'scroll' option is not copied, because it depends on the window height.
8956 * The 'previewwindow' option is reset, there can be only one preview window.
8957 */
8958 void
8959copy_winopt(from, to)
8960 winopt_T *from;
8961 winopt_T *to;
8962{
8963#ifdef FEAT_ARABIC
8964 to->wo_arab = from->wo_arab;
8965#endif
8966 to->wo_list = from->wo_list;
8967 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008968#ifdef FEAT_LINEBREAK
8969 to->wo_nuw = from->wo_nuw;
8970#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971#ifdef FEAT_RIGHTLEFT
8972 to->wo_rl = from->wo_rl;
8973 to->wo_rlc = vim_strsave(from->wo_rlc);
8974#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008975#ifdef FEAT_STL_OPT
8976 to->wo_stl = vim_strsave(from->wo_stl);
8977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 to->wo_wrap = from->wo_wrap;
8979#ifdef FEAT_LINEBREAK
8980 to->wo_lbr = from->wo_lbr;
8981#endif
8982#ifdef FEAT_SCROLLBIND
8983 to->wo_scb = from->wo_scb;
8984#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008985#ifdef FEAT_SYN_HL
8986 to->wo_spell = from->wo_spell;
8987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008988#ifdef FEAT_DIFF
8989 to->wo_diff = from->wo_diff;
8990#endif
8991#ifdef FEAT_FOLDING
8992 to->wo_fdc = from->wo_fdc;
8993 to->wo_fen = from->wo_fen;
8994 to->wo_fdi = vim_strsave(from->wo_fdi);
8995 to->wo_fml = from->wo_fml;
8996 to->wo_fdl = from->wo_fdl;
8997 to->wo_fdm = vim_strsave(from->wo_fdm);
8998 to->wo_fdn = from->wo_fdn;
8999# ifdef FEAT_EVAL
9000 to->wo_fde = vim_strsave(from->wo_fde);
9001 to->wo_fdt = vim_strsave(from->wo_fdt);
9002# endif
9003 to->wo_fmr = vim_strsave(from->wo_fmr);
9004#endif
9005 check_winopt(to); /* don't want NULL pointers */
9006}
9007
9008/*
9009 * Check string options in a window for a NULL value.
9010 */
9011 void
9012check_win_options(win)
9013 win_T *win;
9014{
9015 check_winopt(&win->w_onebuf_opt);
9016 check_winopt(&win->w_allbuf_opt);
9017}
9018
9019/*
9020 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9021 */
9022/*ARGSUSED*/
9023 void
9024check_winopt(wop)
9025 winopt_T *wop;
9026{
9027#ifdef FEAT_FOLDING
9028 check_string_option(&wop->wo_fdi);
9029 check_string_option(&wop->wo_fdm);
9030# ifdef FEAT_EVAL
9031 check_string_option(&wop->wo_fde);
9032 check_string_option(&wop->wo_fdt);
9033# endif
9034 check_string_option(&wop->wo_fmr);
9035#endif
9036#ifdef FEAT_RIGHTLEFT
9037 check_string_option(&wop->wo_rlc);
9038#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009039#ifdef FEAT_STL_OPT
9040 check_string_option(&wop->wo_stl);
9041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009042}
9043
9044/*
9045 * Free the allocated memory inside a winopt_T.
9046 */
9047/*ARGSUSED*/
9048 void
9049clear_winopt(wop)
9050 winopt_T *wop;
9051{
9052#ifdef FEAT_FOLDING
9053 clear_string_option(&wop->wo_fdi);
9054 clear_string_option(&wop->wo_fdm);
9055# ifdef FEAT_EVAL
9056 clear_string_option(&wop->wo_fde);
9057 clear_string_option(&wop->wo_fdt);
9058# endif
9059 clear_string_option(&wop->wo_fmr);
9060#endif
9061#ifdef FEAT_RIGHTLEFT
9062 clear_string_option(&wop->wo_rlc);
9063#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009064#ifdef FEAT_STL_OPT
9065 clear_string_option(&wop->wo_stl);
9066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067}
9068
9069/*
9070 * Copy global option values to local options for one buffer.
9071 * Used when creating a new buffer and sometimes when entering a buffer.
9072 * flags:
9073 * BCO_ENTER We will enter the buf buffer.
9074 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9075 * appropriate.
9076 * BCO_NOHELP Don't copy the values to a help buffer.
9077 */
9078 void
9079buf_copy_options(buf, flags)
9080 buf_T *buf;
9081 int flags;
9082{
9083 int should_copy = TRUE;
9084 char_u *save_p_isk = NULL; /* init for GCC */
9085 int dont_do_help;
9086 int did_isk = FALSE;
9087
9088 /*
9089 * Don't do anything of the buffer is invalid.
9090 */
9091 if (buf == NULL || !buf_valid(buf))
9092 return;
9093
9094 /*
9095 * Skip this when the option defaults have not been set yet. Happens when
9096 * main() allocates the first buffer.
9097 */
9098 if (p_cpo != NULL)
9099 {
9100 /*
9101 * Always copy when entering and 'cpo' contains 'S'.
9102 * Don't copy when already initialized.
9103 * Don't copy when 'cpo' contains 's' and not entering.
9104 * 'S' BCO_ENTER initialized 's' should_copy
9105 * yes yes X X TRUE
9106 * yes no yes X FALSE
9107 * no X yes X FALSE
9108 * X no no yes FALSE
9109 * X no no no TRUE
9110 * no yes no X TRUE
9111 */
9112 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9113 && (buf->b_p_initialized
9114 || (!(flags & BCO_ENTER)
9115 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9116 should_copy = FALSE;
9117
9118 if (should_copy || (flags & BCO_ALWAYS))
9119 {
9120 /* Don't copy the options specific to a help buffer when
9121 * BCO_NOHELP is given or the options were initialized already
9122 * (jumping back to a help file with CTRL-T or CTRL-O) */
9123 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9124 || buf->b_p_initialized;
9125 if (dont_do_help) /* don't free b_p_isk */
9126 {
9127 save_p_isk = buf->b_p_isk;
9128 buf->b_p_isk = NULL;
9129 }
9130 /*
9131 * Always free the allocated strings.
9132 * If not already initialized, set 'readonly' and copy 'fileformat'.
9133 */
9134 if (!buf->b_p_initialized)
9135 {
9136 free_buf_options(buf, TRUE);
9137 buf->b_p_ro = FALSE; /* don't copy readonly */
9138 buf->b_p_tx = p_tx;
9139#ifdef FEAT_MBYTE
9140 buf->b_p_fenc = vim_strsave(p_fenc);
9141#endif
9142 buf->b_p_ff = vim_strsave(p_ff);
9143#if defined(FEAT_QUICKFIX)
9144 buf->b_p_bh = empty_option;
9145 buf->b_p_bt = empty_option;
9146#endif
9147 }
9148 else
9149 free_buf_options(buf, FALSE);
9150
9151 buf->b_p_ai = p_ai;
9152 buf->b_p_ai_nopaste = p_ai_nopaste;
9153 buf->b_p_sw = p_sw;
9154 buf->b_p_tw = p_tw;
9155 buf->b_p_tw_nopaste = p_tw_nopaste;
9156 buf->b_p_tw_nobin = p_tw_nobin;
9157 buf->b_p_wm = p_wm;
9158 buf->b_p_wm_nopaste = p_wm_nopaste;
9159 buf->b_p_wm_nobin = p_wm_nobin;
9160 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009161#ifdef FEAT_MBYTE
9162 buf->b_p_bomb = p_bomb;
9163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164 buf->b_p_et = p_et;
9165 buf->b_p_et_nobin = p_et_nobin;
9166 buf->b_p_ml = p_ml;
9167 buf->b_p_ml_nobin = p_ml_nobin;
9168 buf->b_p_inf = p_inf;
9169 buf->b_p_swf = p_swf;
9170#ifdef FEAT_INS_EXPAND
9171 buf->b_p_cpt = vim_strsave(p_cpt);
9172#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009173#ifdef FEAT_COMPL_FUNC
9174 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009175 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009177 buf->b_p_sts = p_sts;
9178 buf->b_p_sts_nopaste = p_sts_nopaste;
9179#ifndef SHORT_FNAME
9180 buf->b_p_sn = p_sn;
9181#endif
9182#ifdef FEAT_COMMENTS
9183 buf->b_p_com = vim_strsave(p_com);
9184#endif
9185#ifdef FEAT_FOLDING
9186 buf->b_p_cms = vim_strsave(p_cms);
9187#endif
9188 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009189 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009190 buf->b_p_nf = vim_strsave(p_nf);
9191 buf->b_p_mps = vim_strsave(p_mps);
9192#ifdef FEAT_SMARTINDENT
9193 buf->b_p_si = p_si;
9194#endif
9195 buf->b_p_ci = p_ci;
9196#ifdef FEAT_CINDENT
9197 buf->b_p_cin = p_cin;
9198 buf->b_p_cink = vim_strsave(p_cink);
9199 buf->b_p_cino = vim_strsave(p_cino);
9200#endif
9201#ifdef FEAT_AUTOCMD
9202 /* Don't copy 'filetype', it must be detected */
9203 buf->b_p_ft = empty_option;
9204#endif
9205#ifdef FEAT_OSFILETYPE
9206 buf->b_p_oft = vim_strsave(p_oft);
9207#endif
9208 buf->b_p_pi = p_pi;
9209#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9210 buf->b_p_cinw = vim_strsave(p_cinw);
9211#endif
9212#ifdef FEAT_LISP
9213 buf->b_p_lisp = p_lisp;
9214#endif
9215#ifdef FEAT_SYN_HL
9216 /* Don't copy 'syntax', it must be set */
9217 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009218 buf->b_p_smc = p_smc;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009219 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009220 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009221 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009222 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009223#endif
9224#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9225 buf->b_p_inde = vim_strsave(p_inde);
9226 buf->b_p_indk = vim_strsave(p_indk);
9227#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009228#if defined(FEAT_EVAL)
9229 buf->b_p_fex = vim_strsave(p_fex);
9230#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231#ifdef FEAT_CRYPT
9232 buf->b_p_key = vim_strsave(p_key);
9233#endif
9234#ifdef FEAT_SEARCHPATH
9235 buf->b_p_sua = vim_strsave(p_sua);
9236#endif
9237#ifdef FEAT_KEYMAP
9238 buf->b_p_keymap = vim_strsave(p_keymap);
9239 buf->b_kmap_state |= KEYMAP_INIT;
9240#endif
9241 /* This isn't really an option, but copying the langmap and IME
9242 * state from the current buffer is better than resetting it. */
9243 buf->b_p_iminsert = p_iminsert;
9244 buf->b_p_imsearch = p_imsearch;
9245
9246 /* options that are normally global but also have a local value
9247 * are not copied, start using the global value */
9248 buf->b_p_ar = -1;
9249#ifdef FEAT_QUICKFIX
9250 buf->b_p_gp = empty_option;
9251 buf->b_p_mp = empty_option;
9252 buf->b_p_efm = empty_option;
9253#endif
9254 buf->b_p_ep = empty_option;
9255 buf->b_p_kp = empty_option;
9256 buf->b_p_path = empty_option;
9257 buf->b_p_tags = empty_option;
9258#ifdef FEAT_FIND_ID
9259 buf->b_p_def = empty_option;
9260 buf->b_p_inc = empty_option;
9261# ifdef FEAT_EVAL
9262 buf->b_p_inex = vim_strsave(p_inex);
9263# endif
9264#endif
9265#ifdef FEAT_INS_EXPAND
9266 buf->b_p_dict = empty_option;
9267 buf->b_p_tsr = empty_option;
9268#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009269#ifdef FEAT_TEXTOBJ
9270 buf->b_p_qe = vim_strsave(p_qe);
9271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009272
9273 /*
9274 * Don't copy the options set by ex_help(), use the saved values,
9275 * when going from a help buffer to a non-help buffer.
9276 * Don't touch these at all when BCO_NOHELP is used and going from
9277 * or to a help buffer.
9278 */
9279 if (dont_do_help)
9280 buf->b_p_isk = save_p_isk;
9281 else
9282 {
9283 buf->b_p_isk = vim_strsave(p_isk);
9284 did_isk = TRUE;
9285 buf->b_p_ts = p_ts;
9286 buf->b_help = FALSE;
9287#ifdef FEAT_QUICKFIX
9288 if (buf->b_p_bt[0] == 'h')
9289 clear_string_option(&buf->b_p_bt);
9290#endif
9291 buf->b_p_ma = p_ma;
9292 }
9293 }
9294
9295 /*
9296 * When the options should be copied (ignoring BCO_ALWAYS), set the
9297 * flag that indicates that the options have been initialized.
9298 */
9299 if (should_copy)
9300 buf->b_p_initialized = TRUE;
9301 }
9302
9303 check_buf_options(buf); /* make sure we don't have NULLs */
9304 if (did_isk)
9305 (void)buf_init_chartab(buf, FALSE);
9306}
9307
9308/*
9309 * Reset the 'modifiable' option and its default value.
9310 */
9311 void
9312reset_modifiable()
9313{
9314 int opt_idx;
9315
9316 curbuf->b_p_ma = FALSE;
9317 p_ma = FALSE;
9318 opt_idx = findoption((char_u *)"ma");
9319 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9320}
9321
9322/*
9323 * Set the global value for 'iminsert' to the local value.
9324 */
9325 void
9326set_iminsert_global()
9327{
9328 p_iminsert = curbuf->b_p_iminsert;
9329}
9330
9331/*
9332 * Set the global value for 'imsearch' to the local value.
9333 */
9334 void
9335set_imsearch_global()
9336{
9337 p_imsearch = curbuf->b_p_imsearch;
9338}
9339
9340#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9341static int expand_option_idx = -1;
9342static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9343static int expand_option_flags = 0;
9344
9345 void
9346set_context_in_set_cmd(xp, arg, opt_flags)
9347 expand_T *xp;
9348 char_u *arg;
9349 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9350{
9351 int nextchar;
9352 long_u flags = 0; /* init for GCC */
9353 int opt_idx = 0; /* init for GCC */
9354 char_u *p;
9355 char_u *s;
9356 int is_term_option = FALSE;
9357 int key;
9358
9359 expand_option_flags = opt_flags;
9360
9361 xp->xp_context = EXPAND_SETTINGS;
9362 if (*arg == NUL)
9363 {
9364 xp->xp_pattern = arg;
9365 return;
9366 }
9367 p = arg + STRLEN(arg) - 1;
9368 if (*p == ' ' && *(p - 1) != '\\')
9369 {
9370 xp->xp_pattern = p + 1;
9371 return;
9372 }
9373 while (p > arg)
9374 {
9375 s = p;
9376 /* count number of backslashes before ' ' or ',' */
9377 if (*p == ' ' || *p == ',')
9378 {
9379 while (s > arg && *(s - 1) == '\\')
9380 --s;
9381 }
9382 /* break at a space with an even number of backslashes */
9383 if (*p == ' ' && ((p - s) & 1) == 0)
9384 {
9385 ++p;
9386 break;
9387 }
9388 --p;
9389 }
9390 if (STRNCMP(p, "no", 2) == 0)
9391 {
9392 xp->xp_context = EXPAND_BOOL_SETTINGS;
9393 p += 2;
9394 }
9395 if (STRNCMP(p, "inv", 3) == 0)
9396 {
9397 xp->xp_context = EXPAND_BOOL_SETTINGS;
9398 p += 3;
9399 }
9400 xp->xp_pattern = arg = p;
9401 if (*arg == '<')
9402 {
9403 while (*p != '>')
9404 if (*p++ == NUL) /* expand terminal option name */
9405 return;
9406 key = get_special_key_code(arg + 1);
9407 if (key == 0) /* unknown name */
9408 {
9409 xp->xp_context = EXPAND_NOTHING;
9410 return;
9411 }
9412 nextchar = *++p;
9413 is_term_option = TRUE;
9414 expand_option_name[2] = KEY2TERMCAP0(key);
9415 expand_option_name[3] = KEY2TERMCAP1(key);
9416 }
9417 else
9418 {
9419 if (p[0] == 't' && p[1] == '_')
9420 {
9421 p += 2;
9422 if (*p != NUL)
9423 ++p;
9424 if (*p == NUL)
9425 return; /* expand option name */
9426 nextchar = *++p;
9427 is_term_option = TRUE;
9428 expand_option_name[2] = p[-2];
9429 expand_option_name[3] = p[-1];
9430 }
9431 else
9432 {
9433 /* Allow * wildcard */
9434 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9435 p++;
9436 if (*p == NUL)
9437 return;
9438 nextchar = *p;
9439 *p = NUL;
9440 opt_idx = findoption(arg);
9441 *p = nextchar;
9442 if (opt_idx == -1 || options[opt_idx].var == NULL)
9443 {
9444 xp->xp_context = EXPAND_NOTHING;
9445 return;
9446 }
9447 flags = options[opt_idx].flags;
9448 if (flags & P_BOOL)
9449 {
9450 xp->xp_context = EXPAND_NOTHING;
9451 return;
9452 }
9453 }
9454 }
9455 /* handle "-=" and "+=" */
9456 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9457 {
9458 ++p;
9459 nextchar = '=';
9460 }
9461 if ((nextchar != '=' && nextchar != ':')
9462 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9463 {
9464 xp->xp_context = EXPAND_UNSUCCESSFUL;
9465 return;
9466 }
9467 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9468 {
9469 xp->xp_context = EXPAND_OLD_SETTING;
9470 if (is_term_option)
9471 expand_option_idx = -1;
9472 else
9473 expand_option_idx = opt_idx;
9474 xp->xp_pattern = p + 1;
9475 return;
9476 }
9477 xp->xp_context = EXPAND_NOTHING;
9478 if (is_term_option || (flags & P_NUM))
9479 return;
9480
9481 xp->xp_pattern = p + 1;
9482
9483 if (flags & P_EXPAND)
9484 {
9485 p = options[opt_idx].var;
9486 if (p == (char_u *)&p_bdir
9487 || p == (char_u *)&p_dir
9488 || p == (char_u *)&p_path
9489 || p == (char_u *)&p_rtp
9490#ifdef FEAT_SEARCHPATH
9491 || p == (char_u *)&p_cdpath
9492#endif
9493#ifdef FEAT_SESSION
9494 || p == (char_u *)&p_vdir
9495#endif
9496 )
9497 {
9498 xp->xp_context = EXPAND_DIRECTORIES;
9499 if (p == (char_u *)&p_path
9500#ifdef FEAT_SEARCHPATH
9501 || p == (char_u *)&p_cdpath
9502#endif
9503 )
9504 xp->xp_backslash = XP_BS_THREE;
9505 else
9506 xp->xp_backslash = XP_BS_ONE;
9507 }
9508 else
9509 {
9510 xp->xp_context = EXPAND_FILES;
9511 /* for 'tags' need three backslashes for a space */
9512 if (p == (char_u *)&p_tags)
9513 xp->xp_backslash = XP_BS_THREE;
9514 else
9515 xp->xp_backslash = XP_BS_ONE;
9516 }
9517 }
9518
9519 /* For an option that is a list of file names, find the start of the
9520 * last file name. */
9521 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9522 {
9523 /* count number of backslashes before ' ' or ',' */
9524 if (*p == ' ' || *p == ',')
9525 {
9526 s = p;
9527 while (s > xp->xp_pattern && *(s - 1) == '\\')
9528 --s;
9529 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9530 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9531 {
9532 xp->xp_pattern = p + 1;
9533 break;
9534 }
9535 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009536
9537#ifdef FEAT_SYN_HL
9538 /* for 'spellsuggest' start at "file:" */
9539 if (options[opt_idx].var == (char_u *)&p_sps
9540 && STRNCMP(p, "file:", 5) == 0)
9541 {
9542 xp->xp_pattern = p + 5;
9543 break;
9544 }
9545#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546 }
9547
9548 return;
9549}
9550
9551 int
9552ExpandSettings(xp, regmatch, num_file, file)
9553 expand_T *xp;
9554 regmatch_T *regmatch;
9555 int *num_file;
9556 char_u ***file;
9557{
9558 int num_normal = 0; /* Nr of matching non-term-code settings */
9559 int num_term = 0; /* Nr of matching terminal code settings */
9560 int opt_idx;
9561 int match;
9562 int count = 0;
9563 char_u *str;
9564 int loop;
9565 int is_term_opt;
9566 char_u name_buf[MAX_KEY_NAME_LEN];
9567 static char *(names[]) = {"all", "termcap"};
9568 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9569
9570 /* do this loop twice:
9571 * loop == 0: count the number of matching options
9572 * loop == 1: copy the matching options into allocated memory
9573 */
9574 for (loop = 0; loop <= 1; ++loop)
9575 {
9576 regmatch->rm_ic = ic;
9577 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9578 {
9579 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9580 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9581 {
9582 if (loop == 0)
9583 num_normal++;
9584 else
9585 (*file)[count++] = vim_strsave((char_u *)names[match]);
9586 }
9587 }
9588 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9589 opt_idx++)
9590 {
9591 if (options[opt_idx].var == NULL)
9592 continue;
9593 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9594 && !(options[opt_idx].flags & P_BOOL))
9595 continue;
9596 is_term_opt = istermoption(&options[opt_idx]);
9597 if (is_term_opt && num_normal > 0)
9598 continue;
9599 match = FALSE;
9600 if (vim_regexec(regmatch, str, (colnr_T)0)
9601 || (options[opt_idx].shortname != NULL
9602 && vim_regexec(regmatch,
9603 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9604 match = TRUE;
9605 else if (is_term_opt)
9606 {
9607 name_buf[0] = '<';
9608 name_buf[1] = 't';
9609 name_buf[2] = '_';
9610 name_buf[3] = str[2];
9611 name_buf[4] = str[3];
9612 name_buf[5] = '>';
9613 name_buf[6] = NUL;
9614 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9615 {
9616 match = TRUE;
9617 str = name_buf;
9618 }
9619 }
9620 if (match)
9621 {
9622 if (loop == 0)
9623 {
9624 if (is_term_opt)
9625 num_term++;
9626 else
9627 num_normal++;
9628 }
9629 else
9630 (*file)[count++] = vim_strsave(str);
9631 }
9632 }
9633 /*
9634 * Check terminal key codes, these are not in the option table
9635 */
9636 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9637 {
9638 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9639 {
9640 if (!isprint(str[0]) || !isprint(str[1]))
9641 continue;
9642
9643 name_buf[0] = 't';
9644 name_buf[1] = '_';
9645 name_buf[2] = str[0];
9646 name_buf[3] = str[1];
9647 name_buf[4] = NUL;
9648
9649 match = FALSE;
9650 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9651 match = TRUE;
9652 else
9653 {
9654 name_buf[0] = '<';
9655 name_buf[1] = 't';
9656 name_buf[2] = '_';
9657 name_buf[3] = str[0];
9658 name_buf[4] = str[1];
9659 name_buf[5] = '>';
9660 name_buf[6] = NUL;
9661
9662 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9663 match = TRUE;
9664 }
9665 if (match)
9666 {
9667 if (loop == 0)
9668 num_term++;
9669 else
9670 (*file)[count++] = vim_strsave(name_buf);
9671 }
9672 }
9673
9674 /*
9675 * Check special key names.
9676 */
9677 regmatch->rm_ic = TRUE; /* ignore case here */
9678 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9679 {
9680 name_buf[0] = '<';
9681 STRCPY(name_buf + 1, str);
9682 STRCAT(name_buf, ">");
9683
9684 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9685 {
9686 if (loop == 0)
9687 num_term++;
9688 else
9689 (*file)[count++] = vim_strsave(name_buf);
9690 }
9691 }
9692 }
9693 if (loop == 0)
9694 {
9695 if (num_normal > 0)
9696 *num_file = num_normal;
9697 else if (num_term > 0)
9698 *num_file = num_term;
9699 else
9700 return OK;
9701 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9702 if (*file == NULL)
9703 {
9704 *file = (char_u **)"";
9705 return FAIL;
9706 }
9707 }
9708 }
9709 return OK;
9710}
9711
9712 int
9713ExpandOldSetting(num_file, file)
9714 int *num_file;
9715 char_u ***file;
9716{
9717 char_u *var = NULL; /* init for GCC */
9718 char_u *buf;
9719
9720 *num_file = 0;
9721 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9722 if (*file == NULL)
9723 return FAIL;
9724
9725 /*
9726 * For a terminal key code expand_option_idx is < 0.
9727 */
9728 if (expand_option_idx < 0)
9729 {
9730 var = find_termcode(expand_option_name + 2);
9731 if (var == NULL)
9732 expand_option_idx = findoption(expand_option_name);
9733 }
9734
9735 if (expand_option_idx >= 0)
9736 {
9737 /* put string of option value in NameBuff */
9738 option_value2string(&options[expand_option_idx], expand_option_flags);
9739 var = NameBuff;
9740 }
9741 else if (var == NULL)
9742 var = (char_u *)"";
9743
9744 /* A backslash is required before some characters. This is the reverse of
9745 * what happens in do_set(). */
9746 buf = vim_strsave_escaped(var, escape_chars);
9747
9748 if (buf == NULL)
9749 {
9750 vim_free(*file);
9751 *file = NULL;
9752 return FAIL;
9753 }
9754
9755#ifdef BACKSLASH_IN_FILENAME
9756 /* For MS-Windows et al. we don't double backslashes at the start and
9757 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009758 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 if (var[0] == '\\' && var[1] == '\\'
9760 && expand_option_idx >= 0
9761 && (options[expand_option_idx].flags & P_EXPAND)
9762 && vim_isfilec(var[2])
9763 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9764 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765#endif
9766
9767 *file[0] = buf;
9768 *num_file = 1;
9769 return OK;
9770}
9771#endif
9772
9773/*
9774 * Get the value for the numeric or string option *opp in a nice format into
9775 * NameBuff[]. Must not be called with a hidden option!
9776 */
9777 static void
9778option_value2string(opp, opt_flags)
9779 struct vimoption *opp;
9780 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9781{
9782 char_u *varp;
9783
9784 varp = get_varp_scope(opp, opt_flags);
9785
9786 if (opp->flags & P_NUM)
9787 {
9788 long wc = 0;
9789
9790 if (wc_use_keyname(varp, &wc))
9791 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9792 else if (wc != 0)
9793 STRCPY(NameBuff, transchar((int)wc));
9794 else
9795 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9796 }
9797 else /* P_STRING */
9798 {
9799 varp = *(char_u **)(varp);
9800 if (varp == NULL) /* just in case */
9801 NameBuff[0] = NUL;
9802#ifdef FEAT_CRYPT
9803 /* don't show the actual value of 'key', only that it's set */
9804 if (opp->var == (char_u *)&p_key && *varp)
9805 STRCPY(NameBuff, "*****");
9806#endif
9807 else if (opp->flags & P_EXPAND)
9808 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9809 /* Translate 'pastetoggle' into special key names */
9810 else if ((char_u **)opp->var == &p_pt)
9811 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9812 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009813 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009814 }
9815}
9816
9817/*
9818 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9819 * printed as a keyname.
9820 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9821 */
9822 static int
9823wc_use_keyname(varp, wcp)
9824 char_u *varp;
9825 long *wcp;
9826{
9827 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9828 {
9829 *wcp = *(long *)varp;
9830 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9831 return TRUE;
9832 }
9833 return FALSE;
9834}
9835
9836#ifdef FEAT_LANGMAP
9837/*
9838 * Any character has an equivalent character. This is used for keyboards that
9839 * have a special language mode that sends characters above 128 (although
9840 * other characters can be translated too).
9841 */
9842
9843/*
9844 * char_u langmap_mapchar[256];
9845 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9846 * "translate" native lang chars in normal mode or some cases of
9847 * insert mode without having to tediously switch lang mode back&forth.
9848 */
9849
9850 static void
9851langmap_init()
9852{
9853 int i;
9854
9855 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9856 langmap_mapchar[i] = i;
9857}
9858
9859/*
9860 * Called when langmap option is set; the language map can be
9861 * changed at any time!
9862 */
9863 static void
9864langmap_set()
9865{
9866 char_u *p;
9867 char_u *p2;
9868 int from, to;
9869
9870 langmap_init(); /* back to one-to-one map first */
9871
9872 for (p = p_langmap; p[0] != NUL; )
9873 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009874 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9875 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876 {
9877 if (p2[0] == '\\' && p2[1] != NUL)
9878 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009879 }
9880 if (p2[0] == ';')
9881 ++p2; /* abcd;ABCD form, p2 points to A */
9882 else
9883 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9884 while (p[0])
9885 {
9886 if (p[0] == '\\' && p[1] != NUL)
9887 ++p;
9888#ifdef FEAT_MBYTE
9889 from = (*mb_ptr2char)(p);
9890#else
9891 from = p[0];
9892#endif
9893 if (p2 == NULL)
9894 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009895 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896 if (p[0] == '\\')
9897 ++p;
9898#ifdef FEAT_MBYTE
9899 to = (*mb_ptr2char)(p);
9900#else
9901 to = p[0];
9902#endif
9903 }
9904 else
9905 {
9906 if (p2[0] == '\\')
9907 ++p2;
9908#ifdef FEAT_MBYTE
9909 to = (*mb_ptr2char)(p2);
9910#else
9911 to = p2[0];
9912#endif
9913 }
9914 if (to == NUL)
9915 {
9916 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9917 transchar(from));
9918 return;
9919 }
9920 langmap_mapchar[from & 255] = to;
9921
9922 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009923 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 if (p2 == NULL)
9925 {
9926 if (p[0] == ',')
9927 {
9928 ++p;
9929 break;
9930 }
9931 }
9932 else
9933 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009934 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009935 if (*p == ';')
9936 {
9937 p = p2;
9938 if (p[0] != NUL)
9939 {
9940 if (p[0] != ',')
9941 {
9942 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9943 return;
9944 }
9945 ++p;
9946 }
9947 break;
9948 }
9949 }
9950 }
9951 }
9952}
9953#endif
9954
9955/*
9956 * Return TRUE if format option 'x' is in effect.
9957 * Take care of no formatting when 'paste' is set.
9958 */
9959 int
9960has_format_option(x)
9961 int x;
9962{
9963 if (p_paste)
9964 return FALSE;
9965 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9966}
9967
9968/*
9969 * Return TRUE if "x" is present in 'shortmess' option, or
9970 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9971 */
9972 int
9973shortmess(x)
9974 int x;
9975{
9976 return ( vim_strchr(p_shm, x) != NULL
9977 || (vim_strchr(p_shm, 'a') != NULL
9978 && vim_strchr((char_u *)SHM_A, x) != NULL));
9979}
9980
9981/*
9982 * paste_option_changed() - Called after p_paste was set or reset.
9983 */
9984 static void
9985paste_option_changed()
9986{
9987 static int old_p_paste = FALSE;
9988 static int save_sm = 0;
9989#ifdef FEAT_CMDL_INFO
9990 static int save_ru = 0;
9991#endif
9992#ifdef FEAT_RIGHTLEFT
9993 static int save_ri = 0;
9994 static int save_hkmap = 0;
9995#endif
9996 buf_T *buf;
9997
9998 if (p_paste)
9999 {
10000 /*
10001 * Paste switched from off to on.
10002 * Save the current values, so they can be restored later.
10003 */
10004 if (!old_p_paste)
10005 {
10006 /* save options for each buffer */
10007 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10008 {
10009 buf->b_p_tw_nopaste = buf->b_p_tw;
10010 buf->b_p_wm_nopaste = buf->b_p_wm;
10011 buf->b_p_sts_nopaste = buf->b_p_sts;
10012 buf->b_p_ai_nopaste = buf->b_p_ai;
10013 }
10014
10015 /* save global options */
10016 save_sm = p_sm;
10017#ifdef FEAT_CMDL_INFO
10018 save_ru = p_ru;
10019#endif
10020#ifdef FEAT_RIGHTLEFT
10021 save_ri = p_ri;
10022 save_hkmap = p_hkmap;
10023#endif
10024 /* save global values for local buffer options */
10025 p_tw_nopaste = p_tw;
10026 p_wm_nopaste = p_wm;
10027 p_sts_nopaste = p_sts;
10028 p_ai_nopaste = p_ai;
10029 }
10030
10031 /*
10032 * Always set the option values, also when 'paste' is set when it is
10033 * already on.
10034 */
10035 /* set options for each buffer */
10036 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10037 {
10038 buf->b_p_tw = 0; /* textwidth is 0 */
10039 buf->b_p_wm = 0; /* wrapmargin is 0 */
10040 buf->b_p_sts = 0; /* softtabstop is 0 */
10041 buf->b_p_ai = 0; /* no auto-indent */
10042 }
10043
10044 /* set global options */
10045 p_sm = 0; /* no showmatch */
10046#ifdef FEAT_CMDL_INFO
10047# ifdef FEAT_WINDOWS
10048 if (p_ru)
10049 status_redraw_all(); /* redraw to remove the ruler */
10050# endif
10051 p_ru = 0; /* no ruler */
10052#endif
10053#ifdef FEAT_RIGHTLEFT
10054 p_ri = 0; /* no reverse insert */
10055 p_hkmap = 0; /* no Hebrew keyboard */
10056#endif
10057 /* set global values for local buffer options */
10058 p_tw = 0;
10059 p_wm = 0;
10060 p_sts = 0;
10061 p_ai = 0;
10062 }
10063
10064 /*
10065 * Paste switched from on to off: Restore saved values.
10066 */
10067 else if (old_p_paste)
10068 {
10069 /* restore options for each buffer */
10070 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10071 {
10072 buf->b_p_tw = buf->b_p_tw_nopaste;
10073 buf->b_p_wm = buf->b_p_wm_nopaste;
10074 buf->b_p_sts = buf->b_p_sts_nopaste;
10075 buf->b_p_ai = buf->b_p_ai_nopaste;
10076 }
10077
10078 /* restore global options */
10079 p_sm = save_sm;
10080#ifdef FEAT_CMDL_INFO
10081# ifdef FEAT_WINDOWS
10082 if (p_ru != save_ru)
10083 status_redraw_all(); /* redraw to draw the ruler */
10084# endif
10085 p_ru = save_ru;
10086#endif
10087#ifdef FEAT_RIGHTLEFT
10088 p_ri = save_ri;
10089 p_hkmap = save_hkmap;
10090#endif
10091 /* set global values for local buffer options */
10092 p_tw = p_tw_nopaste;
10093 p_wm = p_wm_nopaste;
10094 p_sts = p_sts_nopaste;
10095 p_ai = p_ai_nopaste;
10096 }
10097
10098 old_p_paste = p_paste;
10099}
10100
10101/*
10102 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10103 *
10104 * Reset 'compatible' and set the values for options that didn't get set yet
10105 * to the Vim defaults.
10106 * Don't do this if the 'compatible' option has been set or reset before.
10107 */
10108 void
10109vimrc_found()
10110{
10111 int opt_idx;
10112
10113 if (!option_was_set((char_u *)"cp"))
10114 {
10115 p_cp = FALSE;
10116 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10117 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10118 set_option_default(opt_idx, OPT_FREE, FALSE);
10119 didset_options();
10120 }
10121}
10122
10123/*
10124 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10125 */
10126 void
10127change_compatible(on)
10128 int on;
10129{
10130 if (p_cp != on)
10131 {
10132 p_cp = on;
10133 compatible_set();
10134 }
10135 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
10136}
10137
10138/*
10139 * Return TRUE when option "name" has been set.
10140 */
10141 int
10142option_was_set(name)
10143 char_u *name;
10144{
10145 int idx;
10146
10147 idx = findoption(name);
10148 if (idx < 0) /* unknown option */
10149 return FALSE;
10150 if (options[idx].flags & P_WAS_SET)
10151 return TRUE;
10152 return FALSE;
10153}
10154
10155/*
10156 * compatible_set() - Called when 'compatible' has been set or unset.
10157 *
10158 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10159 * flag) to a Vi compatible value.
10160 * When 'compatible' is unset: Set all options that have a different default
10161 * for Vim (without the P_VI_DEF flag) to that default.
10162 */
10163 static void
10164compatible_set()
10165{
10166 int opt_idx;
10167
10168 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10169 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10170 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10171 set_option_default(opt_idx, OPT_FREE, p_cp);
10172 didset_options();
10173}
10174
10175#ifdef FEAT_LINEBREAK
10176
10177# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10178 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010179 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180# endif
10181
10182/*
10183 * fill_breakat_flags() -- called when 'breakat' changes value.
10184 */
10185 static void
10186fill_breakat_flags()
10187{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010188 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 int i;
10190
10191 for (i = 0; i < 256; i++)
10192 breakat_flags[i] = FALSE;
10193
10194 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010195 for (p = p_breakat; *p; p++)
10196 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197}
10198
10199# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010200 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201# endif
10202
10203#endif
10204
10205/*
10206 * Check an option that can be a range of string values.
10207 *
10208 * Return OK for correct value, FAIL otherwise.
10209 * Empty is always OK.
10210 */
10211 static int
10212check_opt_strings(val, values, list)
10213 char_u *val;
10214 char **values;
10215 int list; /* when TRUE: accept a list of values */
10216{
10217 return opt_strings_flags(val, values, NULL, list);
10218}
10219
10220/*
10221 * Handle an option that can be a range of string values.
10222 * Set a flag in "*flagp" for each string present.
10223 *
10224 * Return OK for correct value, FAIL otherwise.
10225 * Empty is always OK.
10226 */
10227 static int
10228opt_strings_flags(val, values, flagp, list)
10229 char_u *val; /* new value */
10230 char **values; /* array of valid string values */
10231 unsigned *flagp;
10232 int list; /* when TRUE: accept a list of values */
10233{
10234 int i;
10235 int len;
10236 unsigned new_flags = 0;
10237
10238 while (*val)
10239 {
10240 for (i = 0; ; ++i)
10241 {
10242 if (values[i] == NULL) /* val not found in values[] */
10243 return FAIL;
10244
10245 len = (int)STRLEN(values[i]);
10246 if (STRNCMP(values[i], val, len) == 0
10247 && ((list && val[len] == ',') || val[len] == NUL))
10248 {
10249 val += len + (val[len] == ',');
10250 new_flags |= (1 << i);
10251 break; /* check next item in val list */
10252 }
10253 }
10254 }
10255 if (flagp != NULL)
10256 *flagp = new_flags;
10257
10258 return OK;
10259}
10260
10261/*
10262 * Read the 'wildmode' option, fill wim_flags[].
10263 */
10264 static int
10265check_opt_wim()
10266{
10267 char_u new_wim_flags[4];
10268 char_u *p;
10269 int i;
10270 int idx = 0;
10271
10272 for (i = 0; i < 4; ++i)
10273 new_wim_flags[i] = 0;
10274
10275 for (p = p_wim; *p; ++p)
10276 {
10277 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10278 ;
10279 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10280 return FAIL;
10281 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10282 new_wim_flags[idx] |= WIM_LONGEST;
10283 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10284 new_wim_flags[idx] |= WIM_FULL;
10285 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10286 new_wim_flags[idx] |= WIM_LIST;
10287 else
10288 return FAIL;
10289 p += i;
10290 if (*p == NUL)
10291 break;
10292 if (*p == ',')
10293 {
10294 if (idx == 3)
10295 return FAIL;
10296 ++idx;
10297 }
10298 }
10299
10300 /* fill remaining entries with last flag */
10301 while (idx < 3)
10302 {
10303 new_wim_flags[idx + 1] = new_wim_flags[idx];
10304 ++idx;
10305 }
10306
10307 /* only when there are no errors, wim_flags[] is changed */
10308 for (i = 0; i < 4; ++i)
10309 wim_flags[i] = new_wim_flags[i];
10310 return OK;
10311}
10312
10313/*
10314 * Check if backspacing over something is allowed.
10315 */
10316 int
10317can_bs(what)
10318 int what; /* BS_INDENT, BS_EOL or BS_START */
10319{
10320 switch (*p_bs)
10321 {
10322 case '2': return TRUE;
10323 case '1': return (what != BS_START);
10324 case '0': return FALSE;
10325 }
10326 return vim_strchr(p_bs, what) != NULL;
10327}
10328
10329/*
10330 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10331 * the file must be considered changed when the value is different.
10332 */
10333 void
10334save_file_ff(buf)
10335 buf_T *buf;
10336{
10337 buf->b_start_ffc = *buf->b_p_ff;
10338 buf->b_start_eol = buf->b_p_eol;
10339#ifdef FEAT_MBYTE
10340 /* Only use free/alloc when necessary, they take time. */
10341 if (buf->b_start_fenc == NULL
10342 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10343 {
10344 vim_free(buf->b_start_fenc);
10345 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10346 }
10347#endif
10348}
10349
10350/*
10351 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10352 * from when editing started (save_file_ff() called).
10353 * Also when 'endofline' was changed and 'binary' is set.
10354 * Don't consider a new, empty buffer to be changed.
10355 */
10356 int
10357file_ff_differs(buf)
10358 buf_T *buf;
10359{
10360 if ((buf->b_flags & BF_NEW)
10361 && buf->b_ml.ml_line_count == 1
10362 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10363 return FALSE;
10364 if (buf->b_start_ffc != *buf->b_p_ff)
10365 return TRUE;
10366 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10367 return TRUE;
10368#ifdef FEAT_MBYTE
10369 if (buf->b_start_fenc == NULL)
10370 return (*buf->b_p_fenc != NUL);
10371 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10372#else
10373 return FALSE;
10374#endif
10375}
10376
10377/*
10378 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10379 */
10380 int
10381check_ff_value(p)
10382 char_u *p;
10383{
10384 return check_opt_strings(p, p_ff_values, FALSE);
10385}