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