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