home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / src / option.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-05-29  |  228.6 KB  |  9,180 lines

  1. /* 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.
  41.  * PV_BOTH is added: global option which also has a local value.
  42.  */
  43. #define PV_BOTH 0x1000
  44. #define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
  45.  
  46. typedef enum
  47. {
  48.     PV_NONE = 0
  49.     , PV_AI
  50.     , PV_AR
  51.     , PV_ARAB
  52.     , PV_BH
  53.     , PV_BIN
  54.     , PV_BL
  55.     , PV_BOMB
  56.     , PV_BT
  57.     , PV_CI
  58.     , PV_CIN
  59.     , PV_CINK
  60.     , PV_CINO
  61.     , PV_CINW
  62.     , PV_CMS
  63.     , PV_COM
  64.     , PV_CPT
  65.     , PV_DEF
  66.     , PV_DICT
  67.     , PV_DIFF
  68.     , PV_EFM
  69.     , PV_EOL
  70.     , PV_EP
  71.     , PV_ET
  72.     , PV_FDC
  73.     , PV_FDE
  74.     , PV_FDI
  75.     , PV_FDL
  76.     , PV_FDM
  77.     , PV_FDN
  78.     , PV_FDT
  79.     , PV_FEN
  80.     , PV_FENC
  81.     , PV_FF
  82.     , PV_FML
  83.     , PV_FMR
  84.     , PV_FO
  85.     , PV_FT
  86.     , PV_GP
  87.     , PV_IMI
  88.     , PV_IMS
  89.     , PV_INC
  90.     , PV_INDE
  91.     , PV_INDK
  92.     , PV_INEX
  93.     , PV_INF
  94.     , PV_ISK
  95.     , PV_KEY
  96.     , PV_KMAP
  97.     , PV_KP
  98.     , PV_LBR
  99.     , PV_LISP
  100.     , PV_LIST
  101.     , PV_MA
  102.     , PV_ML
  103.     , PV_MOD
  104.     , PV_MP
  105.     , PV_MPS
  106.     , PV_NF
  107.     , PV_NU
  108.     , PV_OFT
  109.     , PV_PATH
  110.     , PV_PI
  111.     , PV_PVW
  112.     , PV_RL
  113.     , PV_RLC
  114.     , PV_RO
  115.     , PV_SCBIND
  116.     , PV_SCROLL
  117.     , PV_SI
  118.     , PV_SN
  119.     , PV_STS
  120.     , PV_SUA
  121.     , PV_SW
  122.     , PV_SWF
  123.     , PV_SYN
  124.     , PV_TAGS
  125.     , PV_TS
  126.     , PV_TSR
  127.     , PV_TW
  128.     , PV_TX
  129.     , PV_WFH
  130.     , PV_WM
  131.     , PV_WRAP
  132. } idopt_T;
  133.  
  134. /*
  135.  * Options local to a window have a value local to a buffer and global to all
  136.  * buffers.  Indicate this by setting "var" to VAR_WIN.
  137.  */
  138. #define VAR_WIN ((char_u *)-1)
  139.  
  140. /*
  141.  * These the global values for options which are also local to a buffer.
  142.  * Only to be used in option.c!
  143.  */
  144. static int    p_ai;
  145. static int    p_bin;
  146. #ifdef FEAT_MBYTE
  147. static int    p_bomb;
  148. #endif
  149. #if defined(FEAT_QUICKFIX)
  150. static char_u    *p_bh;
  151. static char_u    *p_bt;
  152. #endif
  153. static int    p_bl;
  154. static int    p_ci;
  155. #ifdef FEAT_CINDENT
  156. static int    p_cin;
  157. static char_u    *p_cink;
  158. static char_u    *p_cino;
  159. #endif
  160. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  161. static char_u    *p_cinw;
  162. #endif
  163. #ifdef FEAT_COMMENTS
  164. static char_u    *p_com;
  165. #endif
  166. #ifdef FEAT_FOLDING
  167. static char_u    *p_cms;
  168. #endif
  169. #ifdef FEAT_INS_EXPAND
  170. static char_u    *p_cpt;
  171. #endif
  172. static int    p_eol;
  173. static int    p_et;
  174. #ifdef FEAT_MBYTE
  175. static char_u    *p_fenc;
  176. #endif
  177. static char_u    *p_ff;
  178. static char_u    *p_fo;
  179. #ifdef FEAT_AUTOCMD
  180. static char_u    *p_ft;
  181. #endif
  182. static long    p_iminsert;
  183. static long    p_imsearch;
  184. #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
  185. static char_u    *p_inex;
  186. #endif
  187. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  188. static char_u    *p_inde;
  189. static char_u    *p_indk;
  190. #endif
  191. static int    p_inf;
  192. static char_u    *p_isk;
  193. #ifdef FEAT_CRYPT
  194. static char_u    *p_key;
  195. #endif
  196. #ifdef FEAT_LISP
  197. static int    p_lisp;
  198. #endif
  199. static int    p_ml;
  200. static int    p_ma;
  201. static int    p_mod;
  202. static char_u    *p_mps;
  203. static char_u    *p_nf;
  204. #ifdef FEAT_OSFILETYPE
  205. static char_u    *p_oft;
  206. #endif
  207. static int    p_pi;
  208. static int    p_ro;
  209. #ifdef FEAT_SMARTINDENT
  210. static int    p_si;
  211. #endif
  212. #ifndef SHORT_FNAME
  213. static int    p_sn;
  214. #endif
  215. static long    p_sts;
  216. #if defined(FEAT_SEARCHPATH)
  217. static char_u    *p_sua;
  218. #endif
  219. static long    p_sw;
  220. static int    p_swf;
  221. #ifdef FEAT_SYN_HL
  222. static char_u    *p_syn;
  223. #endif
  224. static long    p_ts;
  225. static long    p_tw;
  226. static int    p_tx;
  227. static long    p_wm;
  228. #ifdef FEAT_KEYMAP
  229. static char_u    *p_keymap;
  230. #endif
  231.  
  232. /* Saved values for when 'bin' is set. */
  233. static int    p_et_nobin;
  234. static int    p_ml_nobin;
  235. static long    p_tw_nobin;
  236. static long    p_wm_nobin;
  237.  
  238. /* Saved values for when 'paste' is set */
  239. static long    p_tw_nopaste;
  240. static long    p_wm_nopaste;
  241. static long    p_sts_nopaste;
  242. static int    p_ai_nopaste;
  243.  
  244. struct vimoption
  245. {
  246.     char    *fullname;    /* full option name */
  247.     char    *shortname;    /* permissible abbreviation */
  248.     long_u    flags;        /* see below */
  249.     char_u    *var;        /* global option: pointer to variable;
  250.                  * window-local option: VAR_WIN;
  251.                  * buffer-local option: global value */
  252.     idopt_T    indir;        /* global option: PV_NONE;
  253.                  * local option: indirect option index */
  254.     char_u    *def_val[2];    /* default values for variable (vi and vim) */
  255. #ifdef FEAT_EVAL
  256.     scid_T    scriptID;    /* script in which the option was last set */
  257. #endif
  258. };
  259.  
  260. #define VI_DEFAULT  0        /* def_val[VI_DEFAULT] is Vi default value */
  261. #define VIM_DEFAULT 1        /* def_val[VIM_DEFAULT] is Vim default value */
  262.  
  263. /*
  264.  * Flags
  265.  */
  266. #define P_BOOL        0x01    /* the option is boolean */
  267. #define P_NUM        0x02    /* the option is numeric */
  268. #define P_STRING    0x04    /* the option is a string */
  269. #define P_ALLOCED    0x08    /* the string option is in allocated memory,
  270.                     must use vim_free() when assigning new
  271.                     value. Not set if default is the same. */
  272. #define P_EXPAND    0x10    /* environment expansion.  NOTE: P_EXPAND can
  273.                    never be used for local or hidden options! */
  274. #define P_NODEFAULT    0x40    /* don't set to default value */
  275. #define P_DEF_ALLOCED    0x80    /* default value is in allocated memory, must
  276.                     use vim_free() when assigning new value */
  277. #define P_WAS_SET    0x100    /* option has been set/reset */
  278. #define P_NO_MKRC    0x200    /* don't include in :mkvimrc output */
  279. #define P_VI_DEF    0x400    /* Use Vi default for Vim */
  280. #define P_VIM        0x800    /* Vim option, reset when 'cp' set */
  281.  
  282.                 /* when option changed, what to display: */
  283. #define P_RSTAT        0x1000    /* redraw status lines */
  284. #define P_RWIN        0x2000    /* redraw current window */
  285. #define P_RBUF        0x4000    /* redraw current buffer */
  286. #define P_RALL        0x6000    /* redraw all windows */
  287. #define P_RCLR        0x7000    /* clear and redraw all */
  288.  
  289. #define P_COMMA        0x8000    /* comma separated list */
  290. #define P_NODUP        0x10000L/* don't allow duplicate strings */
  291. #define P_FLAGLIST    0x20000L/* list of single-char flags */
  292.  
  293. #define P_SECURE    0x40000L/* cannot change in modeline or secure mode */
  294. #define P_GETTEXT    0x80000L/* expand default value with _() */
  295.  
  296. /*
  297.  * options[] is initialized here.
  298.  * The order of the options MUST be alphabetic for ":set all" and findoption().
  299.  * All option names MUST start with a lowercase letter (for findoption()).
  300.  * Exception: "t_" options are at the end.
  301.  * The options with a NULL variable are 'hidden': a set command for them is
  302.  * ignored and they are not printed.
  303.  */
  304. static struct vimoption
  305. #ifdef FEAT_GUI_W16
  306.     _far
  307. #endif
  308.     options[] =
  309. {
  310.     {"aleph",        "al",   P_NUM|P_VI_DEF,
  311. #ifdef FEAT_RIGHTLEFT
  312.                 (char_u *)&p_aleph, PV_NONE,
  313. #else
  314.                 (char_u *)NULL, PV_NONE,
  315. #endif
  316.                 {
  317. #if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
  318.                 (char_u *)128L,
  319. #else
  320.                 (char_u *)224L,
  321. #endif
  322.                         (char_u *)0L}},
  323.     {"arabic",        "arab", P_BOOL|P_VI_DEF|P_VIM,
  324. #ifdef FEAT_ARABIC
  325.                 (char_u *)VAR_WIN, PV_ARAB,
  326. #else
  327.                 (char_u *)NULL, PV_NONE,
  328. #endif
  329.                 {(char_u *)FALSE, (char_u *)0L}},
  330.     {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
  331. #ifdef FEAT_ARABIC
  332.                 (char_u *)&p_arshape, PV_NONE,
  333. #else
  334.                 (char_u *)NULL, PV_NONE,
  335. #endif
  336.                 {(char_u *)TRUE, (char_u *)0L}},
  337.     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
  338. #ifdef FEAT_RIGHTLEFT
  339.                 (char_u *)&p_ari, PV_NONE,
  340. #else
  341.                 (char_u *)NULL, PV_NONE,
  342. #endif
  343.                 {(char_u *)FALSE, (char_u *)0L}},
  344.     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
  345. #ifdef FEAT_FKMAP
  346.                 (char_u *)&p_altkeymap, PV_NONE,
  347. #else
  348.                 (char_u *)NULL, PV_NONE,
  349. #endif
  350.                 {(char_u *)FALSE, (char_u *)0L}},
  351.     {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
  352. #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
  353.                 (char_u *)&p_ambw, PV_NONE,
  354.                 {(char_u *)"single", (char_u *)0L}
  355. #else
  356.                 (char_u *)NULL, PV_NONE,
  357.                 {(char_u *)0L, (char_u *)0L}
  358. #endif
  359.                 },
  360. #if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
  361.     {"autochdir",  "acd",   P_BOOL|P_VI_DEF,
  362.                 (char_u *)&p_acd, PV_NONE,
  363.                 {(char_u *)FALSE, (char_u *)0L}},
  364. #endif
  365.     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
  366.                 (char_u *)&p_ai, PV_AI,
  367.                 {(char_u *)FALSE, (char_u *)0L}},
  368.     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
  369.                 (char_u *)NULL, PV_NONE,
  370.                 {(char_u *)FALSE, (char_u *)0L}},
  371.     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
  372.                 (char_u *)&p_ar, OPT_BOTH(PV_AR),
  373.                 {(char_u *)FALSE, (char_u *)0L}},
  374.     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
  375.                 (char_u *)&p_aw, PV_NONE,
  376.                 {(char_u *)FALSE, (char_u *)0L}},
  377.     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
  378.                 (char_u *)&p_awa, PV_NONE,
  379.                 {(char_u *)FALSE, (char_u *)0L}},
  380.     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
  381.                 (char_u *)&p_bg, PV_NONE,
  382.                 {
  383. #if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
  384.                 (char_u *)"dark",
  385. #else
  386.                 (char_u *)"light",
  387. #endif
  388.                         (char_u *)0L}},
  389.     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
  390.                 (char_u *)&p_bs, PV_NONE,
  391.                 {(char_u *)"", (char_u *)0L}},
  392.     {"backup",        "bk",   P_BOOL|P_VI_DEF|P_VIM,
  393.                 (char_u *)&p_bk, PV_NONE,
  394.                 {(char_u *)FALSE, (char_u *)0L}},
  395.     {"backupcopy",  "bkc",  P_STRING|P_VIM,
  396.                 (char_u *)&p_bkc, PV_NONE,
  397. #ifdef UNIX
  398.                 {(char_u *)"yes", (char_u *)"auto"}
  399. #else
  400.                 {(char_u *)"auto", (char_u *)"auto"}
  401. #endif
  402.                 },
  403.     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
  404.                 (char_u *)&p_bdir, PV_NONE,
  405.                 {(char_u *)DFLT_BDIR, (char_u *)0L}},
  406.     {"backupext",   "bex",  P_STRING|P_VI_DEF,
  407.                 (char_u *)&p_bex, PV_NONE,
  408.                 {
  409. #ifdef VMS
  410.                 (char_u *)"_",
  411. #else
  412.                 (char_u *)"~",
  413. #endif
  414.                         (char_u *)0L}},
  415.     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_COMMA,
  416. #ifdef FEAT_WILDIGN
  417.                 (char_u *)&p_bsk, PV_NONE,
  418.                 {(char_u *)"", (char_u *)0L}
  419. #else
  420.                 (char_u *)NULL, PV_NONE,
  421.                 {(char_u *)0L, (char_u *)0L}
  422. #endif
  423.                 },
  424. #ifdef FEAT_BEVAL
  425.     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
  426.                 (char_u *)&p_bdlay, PV_NONE,
  427.                 {(char_u *)600L, (char_u *)0L}},
  428. #endif
  429. #if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
  430.     || defined(FEAT_NETBEANS_INTG))
  431.     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
  432.                 (char_u *)&p_beval, PV_NONE,
  433.                 {(char_u*)FALSE, (char_u *)0L}},
  434. #endif
  435.     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
  436.                 (char_u *)NULL, PV_NONE,
  437.                 {(char_u *)FALSE, (char_u *)0L}},
  438.     {"binary",        "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
  439.                 (char_u *)&p_bin, PV_BIN,
  440.                 {(char_u *)FALSE, (char_u *)0L}},
  441.     {"bioskey",        "biosk",P_BOOL|P_VI_DEF,
  442. #ifdef MSDOS
  443.                 (char_u *)&p_biosk, PV_NONE,
  444. #else
  445.                 (char_u *)NULL, PV_NONE,
  446. #endif
  447.                 {(char_u *)TRUE, (char_u *)0L}},
  448.     {"bomb",        NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
  449. #ifdef FEAT_MBYTE
  450.                 (char_u *)&p_bomb, PV_BOMB,
  451. #else
  452.                 (char_u *)NULL, PV_NONE,
  453. #endif
  454.                 {(char_u *)FALSE, (char_u *)0L}},
  455.     {"breakat",        "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
  456. #ifdef FEAT_LINEBREAK
  457.                 (char_u *)&p_breakat, PV_NONE,
  458.                 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
  459. #else
  460.                 (char_u *)NULL, PV_NONE,
  461.                 {(char_u *)0L, (char_u *)0L}
  462. #endif
  463.                 },
  464.     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
  465. #ifdef FEAT_BROWSE
  466.                 (char_u *)&p_bsdir, PV_NONE,
  467.                 {(char_u *)"last", (char_u *)0L}
  468. #else
  469.                 (char_u *)NULL, PV_NONE,
  470.                 {(char_u *)0L, (char_u *)0L}
  471. #endif
  472.                 },
  473.     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF,
  474. #if defined(FEAT_QUICKFIX)
  475.                 (char_u *)&p_bh, PV_BH,
  476.                 {(char_u *)"", (char_u *)0L}
  477. #else
  478.                 (char_u *)NULL, PV_NONE,
  479.                 {(char_u *)0L, (char_u *)0L}
  480. #endif
  481.                 },
  482.     {"buflisted",   "bl",   P_BOOL|P_VI_DEF,
  483.                 (char_u *)&p_bl, PV_BL,
  484.                 {(char_u *)1L, (char_u *)0L}
  485.                 },
  486.     {"buftype",        "bt",   P_STRING|P_ALLOCED|P_VI_DEF,
  487. #if defined(FEAT_QUICKFIX)
  488.                 (char_u *)&p_bt, PV_BT,
  489.                 {(char_u *)"", (char_u *)0L}
  490. #else
  491.                 (char_u *)NULL, PV_NONE,
  492.                 {(char_u *)0L, (char_u *)0L}
  493. #endif
  494.                 },
  495.     {"casemap",        "cmp",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  496.                 (char_u *)&p_cmp, PV_NONE,
  497.                 {(char_u *)"internal,keepascii", (char_u *)0L}
  498.                 },
  499.     {"cdpath",        "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  500. #ifdef FEAT_SEARCHPATH
  501.                 (char_u *)&p_cdpath, PV_NONE,
  502.                 {(char_u *)",,", (char_u *)0L}
  503. #else
  504.                 (char_u *)NULL, PV_NONE,
  505.                 {(char_u *)0L, (char_u *)0L}
  506. #endif
  507.                 },
  508.     {"cedit",        NULL,   P_STRING,
  509. #ifdef FEAT_CMDWIN
  510.                 (char_u *)&p_cedit, PV_NONE,
  511.                 {(char_u *)"", (char_u *)CTRL_F_STR}
  512. #else
  513.                 (char_u *)NULL, PV_NONE,
  514.                 {(char_u *)0L, (char_u *)0L}
  515. #endif
  516.                 },
  517.     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
  518. #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
  519.                 (char_u *)&p_ccv, PV_NONE,
  520.                 {(char_u *)"", (char_u *)0L}
  521. #else
  522.                 (char_u *)NULL, PV_NONE,
  523.                 {(char_u *)0L, (char_u *)0L}
  524. #endif
  525.                 },
  526.     {"cindent",        "cin",  P_BOOL|P_VI_DEF|P_VIM,
  527. #ifdef FEAT_CINDENT
  528.                 (char_u *)&p_cin, PV_CIN,
  529. #else
  530.                 (char_u *)NULL, PV_NONE,
  531. #endif
  532.                 {(char_u *)FALSE, (char_u *)0L}},
  533.     {"cinkeys",        "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  534. #ifdef FEAT_CINDENT
  535.                 (char_u *)&p_cink, PV_CINK,
  536.                 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
  537. #else
  538.                 (char_u *)NULL, PV_NONE,
  539.                 {(char_u *)0L, (char_u *)0L}
  540. #endif
  541.                 },
  542.     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  543. #ifdef FEAT_CINDENT
  544.                 (char_u *)&p_cino, PV_CINO,
  545. #else
  546.                 (char_u *)NULL, PV_NONE,
  547. #endif
  548.                 {(char_u *)"", (char_u *)0L}},
  549.     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  550. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  551.                 (char_u *)&p_cinw, PV_CINW,
  552.                 {(char_u *)"if,else,while,do,for,switch",
  553.                 (char_u *)0L}
  554. #else
  555.                 (char_u *)NULL, PV_NONE,
  556.                 {(char_u *)0L, (char_u *)0L}
  557. #endif
  558.                 },
  559.     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  560. #ifdef FEAT_CLIPBOARD
  561.                 (char_u *)&p_cb, PV_NONE,
  562. # ifdef FEAT_XCLIPBOARD
  563.                 {(char_u *)"autoselect,exclude:cons\\|linux",
  564.                                    (char_u *)0L}
  565. # else
  566.                 {(char_u *)"", (char_u *)0L}
  567. # endif
  568. #else
  569.                 (char_u *)NULL, PV_NONE,
  570.                 {(char_u *)"", (char_u *)0L}
  571. #endif
  572.                 },
  573.     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
  574.                 (char_u *)&p_ch, PV_NONE,
  575.                 {(char_u *)1L, (char_u *)0L}},
  576.     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
  577. #ifdef FEAT_CMDWIN
  578.                 (char_u *)&p_cwh, PV_NONE,
  579. #else
  580.                 (char_u *)NULL, PV_NONE,
  581. #endif
  582.                 {(char_u *)7L, (char_u *)0L}},
  583.     {"columns",        "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
  584.                 (char_u *)&Columns, PV_NONE,
  585.                 {(char_u *)80L, (char_u *)0L}},
  586.     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  587. #ifdef FEAT_COMMENTS
  588.                 (char_u *)&p_com, PV_COM,
  589.                 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
  590.                 (char_u *)0L}
  591. #else
  592.                 (char_u *)NULL, PV_NONE,
  593.                 {(char_u *)0L, (char_u *)0L}
  594. #endif
  595.                 },
  596.     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
  597. #ifdef FEAT_FOLDING
  598.                 (char_u *)&p_cms, PV_CMS,
  599.                 {(char_u *)"/*%s*/", (char_u *)0L}
  600. #else
  601.                 (char_u *)NULL, PV_NONE,
  602.                 {(char_u *)0L, (char_u *)0L}
  603. #endif
  604.                 },
  605.     {"compatible",  "cp",   P_BOOL|P_RALL,
  606.                 (char_u *)&p_cp, PV_NONE,
  607.                 {(char_u *)TRUE, (char_u *)FALSE}},
  608.     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  609. #ifdef FEAT_INS_EXPAND
  610.                 (char_u *)&p_cpt, PV_CPT,
  611.                 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
  612. #else
  613.                 (char_u *)NULL, PV_NONE,
  614.                 {(char_u *)0L, (char_u *)0L}
  615. #endif
  616.                 },
  617.     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
  618. #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
  619.                 (char_u *)&p_confirm, PV_NONE,
  620. #else
  621.                 (char_u *)NULL, PV_NONE,
  622. #endif
  623.                 {(char_u *)FALSE, (char_u *)0L}},
  624.     {"conskey",        "consk",P_BOOL|P_VI_DEF,
  625. #ifdef MSDOS
  626.                 (char_u *)&p_consk, PV_NONE,
  627. #else
  628.                 (char_u *)NULL, PV_NONE,
  629. #endif
  630.                 {(char_u *)FALSE, (char_u *)0L}},
  631.     {"copyindent",  "ci",   P_BOOL|P_VI_DEF|P_VIM,
  632.                 (char_u *)&p_ci, PV_CI,
  633.                 {(char_u *)FALSE, (char_u *)0L}},
  634.     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
  635.                 (char_u *)&p_cpo, PV_NONE,
  636.                 {(char_u *)CPO_ALL, (char_u *)CPO_DEFAULT}},
  637.     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
  638. #ifdef FEAT_CSCOPE
  639.                 (char_u *)&p_cspc, PV_NONE,
  640. #else
  641.                 (char_u *)NULL, PV_NONE,
  642. #endif
  643.                 {(char_u *)0L, (char_u *)0L}},
  644.     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  645. #ifdef FEAT_CSCOPE
  646.                 (char_u *)&p_csprg, PV_NONE,
  647.                 {(char_u *)"cscope", (char_u *)0L}
  648. #else
  649.                 (char_u *)NULL, PV_NONE,
  650.                 {(char_u *)0L, (char_u *)0L}
  651. #endif
  652.                 },
  653.     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  654. #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
  655.                 (char_u *)&p_csqf, PV_NONE,
  656.                 {(char_u *)"", (char_u *)0L}},
  657. #else
  658.                 (char_u *)NULL, PV_NONE,
  659.                 {(char_u *)0L, (char_u *)0L}},
  660. #endif
  661.     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
  662. #ifdef FEAT_CSCOPE
  663.                 (char_u *)&p_cst, PV_NONE,
  664. #else
  665.                 (char_u *)NULL, PV_NONE,
  666. #endif
  667.                 {(char_u *)0L, (char_u *)0L}},
  668.     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
  669. #ifdef FEAT_CSCOPE
  670.                 (char_u *)&p_csto, PV_NONE,
  671. #else
  672.                 (char_u *)NULL, PV_NONE,
  673. #endif
  674.                 {(char_u *)0L, (char_u *)0L}},
  675.     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
  676. #ifdef FEAT_CSCOPE
  677.                 (char_u *)&p_csverbose, PV_NONE,
  678. #else
  679.                 (char_u *)NULL, PV_NONE,
  680. #endif
  681.                 {(char_u *)0L, (char_u *)0L}},
  682.     {"debug",        NULL,   P_STRING|P_VI_DEF,
  683.                 (char_u *)&p_debug, PV_NONE,
  684.                 {(char_u *)"", (char_u *)0L}},
  685.     {"define",        "def",  P_STRING|P_ALLOCED|P_VI_DEF,
  686. #ifdef FEAT_FIND_ID
  687.                 (char_u *)&p_def, OPT_BOTH(PV_DEF),
  688.                 {(char_u *)"^#\\s*define", (char_u *)0L}
  689. #else
  690.                 (char_u *)NULL, PV_NONE,
  691.                 {(char_u *)NULL, (char_u *)0L}
  692. #endif
  693.                 },
  694.     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
  695. #ifdef FEAT_MBYTE
  696.                 (char_u *)&p_deco, PV_NONE,
  697. #else
  698.                 (char_u *)NULL, PV_NONE,
  699. #endif
  700.                 {(char_u *)FALSE, (char_u *)0L}
  701.                 },
  702.     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  703. #ifdef FEAT_INS_EXPAND
  704.                 (char_u *)&p_dict, OPT_BOTH(PV_DICT),
  705. #else
  706.                 (char_u *)NULL, PV_NONE,
  707. #endif
  708.                 {(char_u *)"", (char_u *)0L}},
  709.     {"diff",        NULL,   P_BOOL|P_VI_DEF|P_RWIN,
  710. #ifdef FEAT_DIFF
  711.                 (char_u *)VAR_WIN, PV_DIFF,
  712. #else
  713.                 (char_u *)NULL, PV_NONE,
  714. #endif
  715.                 {(char_u *)FALSE, (char_u *)0L}},
  716.     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE,
  717. #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
  718.                 (char_u *)&p_dex, PV_NONE,
  719.                 {(char_u *)"", (char_u *)0L}
  720. #else
  721.                 (char_u *)NULL, PV_NONE,
  722.                 {(char_u *)0L, (char_u *)0L}
  723. #endif
  724.                 },
  725.     {"diffopt",        "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
  726. #ifdef FEAT_DIFF
  727.                 (char_u *)&p_dip, PV_NONE,
  728.                 {(char_u *)"filler", (char_u *)NULL}
  729. #else
  730.                 (char_u *)NULL, PV_NONE,
  731.                 {(char_u *)"", (char_u *)NULL}
  732. #endif
  733.                 },
  734.     {"digraph",        "dg",   P_BOOL|P_VI_DEF|P_VIM,
  735. #ifdef FEAT_DIGRAPHS
  736.                 (char_u *)&p_dg, PV_NONE,
  737. #else
  738.                 (char_u *)NULL, PV_NONE,
  739. #endif
  740.                 {(char_u *)FALSE, (char_u *)0L}},
  741.     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
  742.                 (char_u *)&p_dir, PV_NONE,
  743.                 {(char_u *)DFLT_DIR, (char_u *)0L}},
  744.     {"display",        "dy",   P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
  745.                 (char_u *)&p_dy, PV_NONE,
  746.                 {(char_u *)"", (char_u *)0L}},
  747.     {"eadirection", "ead",  P_STRING|P_VI_DEF,
  748. #ifdef FEAT_VERTSPLIT
  749.                 (char_u *)&p_ead, PV_NONE,
  750.                 {(char_u *)"both", (char_u *)0L}
  751. #else
  752.                 (char_u *)NULL, PV_NONE,
  753.                 {(char_u *)NULL, (char_u *)0L}
  754. #endif
  755.                 },
  756.     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
  757.                 (char_u *)&p_ed, PV_NONE,
  758.                 {(char_u *)FALSE, (char_u *)0L}},
  759.     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR,
  760. #ifdef FEAT_MBYTE
  761.                 (char_u *)&p_enc, PV_NONE,
  762.                 {(char_u *)ENC_DFLT, (char_u *)0L}
  763. #else
  764.                 (char_u *)NULL, PV_NONE,
  765.                 {(char_u *)0L, (char_u *)0L}
  766. #endif
  767.                 },
  768.     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
  769.                 (char_u *)&p_eol, PV_EOL,
  770.                 {(char_u *)TRUE, (char_u *)0L}},
  771.     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
  772.                 (char_u *)&p_ea, PV_NONE,
  773.                 {(char_u *)TRUE, (char_u *)0L}},
  774.     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  775.                 (char_u *)&p_ep, OPT_BOTH(PV_EP),
  776.                 {(char_u *)"", (char_u *)0L}},
  777.     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
  778.                 (char_u *)&p_eb, PV_NONE,
  779.                 {(char_u *)FALSE, (char_u *)0L}},
  780.     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  781. #ifdef FEAT_QUICKFIX
  782.                 (char_u *)&p_ef, PV_NONE,
  783.                 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
  784. #else
  785.                 (char_u *)NULL, PV_NONE,
  786.                 {(char_u *)NULL, (char_u *)0L}
  787. #endif
  788.                 },
  789.     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  790. #ifdef FEAT_QUICKFIX
  791.                 (char_u *)&p_efm, OPT_BOTH(PV_EFM),
  792.                 {(char_u *)DFLT_EFM, (char_u *)0L},
  793. #else
  794.                 (char_u *)NULL, PV_NONE,
  795.                 {(char_u *)NULL, (char_u *)0L}
  796. #endif
  797.                 },
  798.     {"esckeys",        "ek",   P_BOOL|P_VIM,
  799.                 (char_u *)&p_ek, PV_NONE,
  800.                 {(char_u *)FALSE, (char_u *)TRUE}},
  801.     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  802. #ifdef FEAT_AUTOCMD
  803.                 (char_u *)&p_ei, PV_NONE,
  804. #else
  805.                 (char_u *)NULL, PV_NONE,
  806. #endif
  807.                 {(char_u *)"", (char_u *)0L}},
  808.     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
  809.                 (char_u *)&p_et, PV_ET,
  810.                 {(char_u *)FALSE, (char_u *)0L}},
  811.     {"exrc",        "ex",   P_BOOL|P_VI_DEF|P_SECURE,
  812.                 (char_u *)&p_exrc, PV_NONE,
  813.                 {(char_u *)FALSE, (char_u *)0L}},
  814.     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
  815. #ifdef FEAT_MBYTE
  816.                 (char_u *)&p_fenc, PV_FENC,
  817.                 {(char_u *)"", (char_u *)0L}
  818. #else
  819.                 (char_u *)NULL, PV_NONE,
  820.                 {(char_u *)0L, (char_u *)0L}
  821. #endif
  822.                 },
  823.     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
  824. #ifdef FEAT_MBYTE
  825.                 (char_u *)&p_fencs, PV_NONE,
  826.                 {(char_u *)"ucs-bom", (char_u *)0L}
  827. #else
  828.                 (char_u *)NULL, PV_NONE,
  829.                 {(char_u *)0L, (char_u *)0L}
  830. #endif
  831.                 },
  832.     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
  833.                 (char_u *)&p_ff, PV_FF,
  834.                 {(char_u *)DFLT_FF, (char_u *)0L}},
  835.     {"fileformats", "ffs",  P_STRING|P_VIM|P_COMMA|P_NODUP,
  836.                 (char_u *)&p_ffs, PV_NONE,
  837.                 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
  838.     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF,
  839. #ifdef FEAT_AUTOCMD
  840.                 (char_u *)&p_ft, PV_FT,
  841.                 {(char_u *)"", (char_u *)0L}
  842. #else
  843.                 (char_u *)NULL, PV_NONE,
  844.                 {(char_u *)0L, (char_u *)0L}
  845. #endif
  846.                 },
  847.     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
  848. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  849.                 (char_u *)&p_fcs, PV_NONE,
  850.                 {(char_u *)"vert:|,fold:-", (char_u *)0L}
  851. #else
  852.                 (char_u *)NULL, PV_NONE,
  853.                 {(char_u *)"", (char_u *)0L}
  854. #endif
  855.                 },
  856.     {"fkmap",        "fk",   P_BOOL|P_VI_DEF,
  857. #ifdef FEAT_FKMAP
  858.                 (char_u *)&p_fkmap, PV_NONE,
  859. #else
  860.                 (char_u *)NULL, PV_NONE,
  861. #endif
  862.                 {(char_u *)FALSE, (char_u *)0L}},
  863.     {"flash",        "fl",   P_BOOL|P_VI_DEF,
  864.                 (char_u *)NULL, PV_NONE,
  865.                 {(char_u *)FALSE, (char_u *)0L}},
  866. #ifdef FEAT_FOLDING
  867.     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
  868.                 (char_u *)&p_fcl, PV_NONE,
  869.                 {(char_u *)"", (char_u *)0L}},
  870.     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
  871.                 (char_u *)VAR_WIN, PV_FDC,
  872.                 {(char_u *)FALSE, (char_u *)0L}},
  873.     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
  874.                 (char_u *)VAR_WIN, PV_FEN,
  875.                 {(char_u *)TRUE, (char_u *)0L}},
  876.     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  877. # ifdef FEAT_EVAL
  878.                 (char_u *)VAR_WIN, PV_FDE,
  879.                 {(char_u *)"0", (char_u *)NULL}
  880. # else
  881.                 (char_u *)NULL, PV_NONE,
  882.                 {(char_u *)NULL, (char_u *)0L}
  883. # endif
  884.                 },
  885.     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  886.                 (char_u *)VAR_WIN, PV_FDI,
  887.                 {(char_u *)"#", (char_u *)NULL}},
  888.     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
  889.                 (char_u *)VAR_WIN, PV_FDL,
  890.                 {(char_u *)0L, (char_u *)0L}},
  891.     {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
  892.                 (char_u *)&p_fdls, PV_NONE,
  893.                 {(char_u *)-1L, (char_u *)0L}},
  894.     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
  895.                                P_RWIN|P_COMMA|P_NODUP,
  896.                 (char_u *)VAR_WIN, PV_FMR,
  897.                 {(char_u *)"{{{,}}}", (char_u *)NULL}},
  898.     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  899.                 (char_u *)VAR_WIN, PV_FDM,
  900.                 {(char_u *)"manual", (char_u *)NULL}},
  901.     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
  902.                 (char_u *)VAR_WIN, PV_FML,
  903.                 {(char_u *)1L, (char_u *)0L}},
  904.     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
  905.                 (char_u *)VAR_WIN, PV_FDN,
  906.                 {(char_u *)20L, (char_u *)0L}},
  907.     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  908.                 (char_u *)&p_fdo, PV_NONE,
  909.          {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
  910.                                    (char_u *)0L}},
  911.     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  912. # ifdef FEAT_EVAL
  913.                 (char_u *)VAR_WIN, PV_FDT,
  914.                 {(char_u *)"foldtext()", (char_u *)NULL}
  915. #else
  916.                 (char_u *)NULL, PV_NONE,
  917.                 {(char_u *)NULL, (char_u *)0L}
  918. #endif
  919.                 },
  920. #endif
  921.     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
  922.                 (char_u *)&p_fo, PV_FO,
  923.                 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
  924.     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  925.                 (char_u *)&p_fp, PV_NONE,
  926.                 {(char_u *)"", (char_u *)0L}},
  927.     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
  928.                 (char_u *)&p_gd, PV_NONE,
  929.                 {(char_u *)FALSE, (char_u *)0L}},
  930.     {"graphic",        "gr",   P_BOOL|P_VI_DEF,
  931.                 (char_u *)NULL, PV_NONE,
  932.                 {(char_u *)FALSE, (char_u *)0L}},
  933.     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  934. #ifdef FEAT_QUICKFIX
  935.                 (char_u *)&p_gefm, PV_NONE,
  936.                 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
  937. #else
  938.                 (char_u *)NULL, PV_NONE,
  939.                 {(char_u *)NULL, (char_u *)0L}
  940. #endif
  941.                 },
  942.     {"grepprg",        "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  943. #ifdef FEAT_QUICKFIX
  944.                 (char_u *)&p_gp, OPT_BOTH(PV_GP),
  945.                 {
  946. # ifdef WIN3264
  947.                 /* may be changed to "grep -n" in os_win32.c */
  948.                 (char_u *)"findstr /n",
  949. # else
  950. #  ifdef UNIX
  951.                 /* Add an extra file name so that grep will always
  952.                  * insert a file name in the match line. */
  953.                 (char_u *)"grep -n $* /dev/null",
  954. #  else
  955. #   ifdef VMS
  956.                 (char_u *)"SEARCH/NUMBERS ",
  957. #   else
  958.                 (char_u *)"grep -n ",
  959. #endif
  960. #endif
  961. # endif
  962.                 (char_u *)0L},
  963. #else
  964.                 (char_u *)NULL, PV_NONE,
  965.                 {(char_u *)NULL, (char_u *)0L}
  966. #endif
  967.                 },
  968.     {"guicursor",    "gcr",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  969. #ifdef CURSOR_SHAPE
  970.                 (char_u *)&p_guicursor, PV_NONE,
  971.                 {
  972. # ifdef FEAT_GUI
  973.                 (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",
  974. # else    /* MSDOS or Win32 console */
  975.                 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
  976. # endif
  977.                     (char_u *)0L}
  978. #else
  979.                 (char_u *)NULL, PV_NONE,
  980.                 {(char_u *)NULL, (char_u *)0L}
  981. #endif
  982.                     },
  983.     {"guifont",        "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
  984. #ifdef FEAT_GUI
  985.                 (char_u *)&p_guifont, PV_NONE,
  986.                 {(char_u *)"", (char_u *)0L}
  987. #else
  988.                 (char_u *)NULL, PV_NONE,
  989.                 {(char_u *)NULL, (char_u *)0L}
  990. #endif
  991.                     },
  992.     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
  993. #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
  994.                 (char_u *)&p_guifontset, PV_NONE,
  995.                 {(char_u *)"", (char_u *)0L}
  996. #else
  997.                 (char_u *)NULL, PV_NONE,
  998.                 {(char_u *)NULL, (char_u *)0L}
  999. #endif
  1000.                     },
  1001.     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
  1002. #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
  1003.                 (char_u *)&p_guifontwide, PV_NONE,
  1004.                 {(char_u *)"", (char_u *)0L}
  1005. #else
  1006.                 (char_u *)NULL, PV_NONE,
  1007.                 {(char_u *)NULL, (char_u *)0L}
  1008. #endif
  1009.                     },
  1010.     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
  1011. #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
  1012.                 (char_u *)&p_ghr, PV_NONE,
  1013. #else
  1014.                 (char_u *)NULL, PV_NONE,
  1015. #endif
  1016.                 {(char_u *)50L, (char_u *)0L}},
  1017.     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
  1018. #if defined(FEAT_GUI)
  1019.                 (char_u *)&p_go, PV_NONE,
  1020. # if defined(UNIX) && !defined(MACOS)
  1021.                 {(char_u *)"agimrLtT", (char_u *)0L}
  1022. # else
  1023.                 {(char_u *)"gmrLtT", (char_u *)0L}
  1024. # endif
  1025. #else
  1026.                 (char_u *)NULL, PV_NONE,
  1027.                 {(char_u *)NULL, (char_u *)0L}
  1028. #endif
  1029.                     },
  1030.     {"guipty",        NULL,   P_BOOL|P_VI_DEF,
  1031. #if defined(FEAT_GUI)
  1032.                 (char_u *)&p_guipty, PV_NONE,
  1033. #else
  1034.                 (char_u *)NULL, PV_NONE,
  1035. #endif
  1036.                 {(char_u *)TRUE, (char_u *)0L}},
  1037.     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
  1038.                 (char_u *)NULL, PV_NONE,
  1039.                 {(char_u *)0L, (char_u *)0L}},
  1040.     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1041.                 (char_u *)&p_hf, PV_NONE,
  1042.                 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
  1043.     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
  1044. #ifdef FEAT_WINDOWS
  1045.                 (char_u *)&p_hh, PV_NONE,
  1046. #else
  1047.                 (char_u *)NULL, PV_NONE,
  1048. #endif
  1049.                 {(char_u *)20L, (char_u *)0L}},
  1050.     {"hidden",        "hid",  P_BOOL|P_VI_DEF,
  1051.                 (char_u *)&p_hid, PV_NONE,
  1052.                 {(char_u *)FALSE, (char_u *)0L}},
  1053.     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
  1054.                 (char_u *)&p_hl, PV_NONE,
  1055.                 {(char_u *)"8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText",
  1056.                 (char_u *)0L}},
  1057.     {"history",        "hi",   P_NUM|P_VIM,
  1058.                 (char_u *)&p_hi, PV_NONE,
  1059.                 {(char_u *)0L, (char_u *)20L}},
  1060.     {"hkmap",        "hk",   P_BOOL|P_VI_DEF|P_VIM,
  1061. #ifdef FEAT_RIGHTLEFT
  1062.                 (char_u *)&p_hkmap, PV_NONE,
  1063. #else
  1064.                 (char_u *)NULL, PV_NONE,
  1065. #endif
  1066.                 {(char_u *)FALSE, (char_u *)0L}},
  1067.     {"hkmapp",        "hkp",  P_BOOL|P_VI_DEF|P_VIM,
  1068. #ifdef FEAT_RIGHTLEFT
  1069.                 (char_u *)&p_hkmapp, PV_NONE,
  1070. #else
  1071.                 (char_u *)NULL, PV_NONE,
  1072. #endif
  1073.                 {(char_u *)FALSE, (char_u *)0L}},
  1074.     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
  1075.                 (char_u *)&p_hls, PV_NONE,
  1076.                 {(char_u *)FALSE, (char_u *)0L}},
  1077.     {"icon",        NULL,   P_BOOL|P_VI_DEF,
  1078. #ifdef FEAT_TITLE
  1079.                 (char_u *)&p_icon, PV_NONE,
  1080. #else
  1081.                 (char_u *)NULL, PV_NONE,
  1082. #endif
  1083.                 {(char_u *)FALSE, (char_u *)0L}},
  1084.     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
  1085. #ifdef FEAT_TITLE
  1086.                 (char_u *)&p_iconstring, PV_NONE,
  1087. #else
  1088.                 (char_u *)NULL, PV_NONE,
  1089. #endif
  1090.                 {(char_u *)"", (char_u *)0L}},
  1091.     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
  1092.                 (char_u *)&p_ic, PV_NONE,
  1093.                 {(char_u *)FALSE, (char_u *)0L}},
  1094.     {"imactivatekey","imak",P_STRING|P_VI_DEF,
  1095. #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
  1096.                 (char_u *)&p_imak, PV_NONE,
  1097. #else
  1098.                 (char_u *)NULL, PV_NONE,
  1099. #endif
  1100.                 {(char_u *)"", (char_u *)0L}},
  1101.     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
  1102. #ifdef USE_IM_CONTROL
  1103.                 (char_u *)&p_imcmdline, PV_NONE,
  1104. #else
  1105.                 (char_u *)NULL, PV_NONE,
  1106. #endif
  1107.                 {(char_u *)FALSE, (char_u *)0L}},
  1108.     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
  1109. #ifdef USE_IM_CONTROL
  1110.                 (char_u *)&p_imdisable, PV_NONE,
  1111. #else
  1112.                 (char_u *)NULL, PV_NONE,
  1113. #endif
  1114. #ifdef __sgi
  1115.                 {(char_u *)TRUE, (char_u *)0L}
  1116. #else
  1117.                 {(char_u *)FALSE, (char_u *)0L}
  1118. #endif
  1119.                 },
  1120.     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
  1121.                 (char_u *)&p_iminsert, PV_IMI,
  1122. #ifdef B_IMODE_IM
  1123.                 {(char_u *)B_IMODE_IM, (char_u *)0L}
  1124. #else
  1125.                 {(char_u *)B_IMODE_NONE, (char_u *)0L}
  1126. #endif
  1127.                 },
  1128.     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
  1129.                 (char_u *)&p_imsearch, PV_IMS,
  1130. #ifdef B_IMODE_IM
  1131.                 {(char_u *)B_IMODE_IM, (char_u *)0L}
  1132. #else
  1133.                 {(char_u *)B_IMODE_NONE, (char_u *)0L}
  1134. #endif
  1135.                 },
  1136.     {"include",        "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
  1137. #ifdef FEAT_FIND_ID
  1138.                 (char_u *)&p_inc, OPT_BOTH(PV_INC),
  1139.                 {(char_u *)"^#\\s*include", (char_u *)0L}
  1140. #else
  1141.                 (char_u *)NULL, PV_NONE,
  1142.                 {(char_u *)0L, (char_u *)0L}
  1143. #endif
  1144.                 },
  1145.     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
  1146. #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
  1147.                 (char_u *)&p_inex, PV_INEX,
  1148.                 {(char_u *)"", (char_u *)0L}
  1149. #else
  1150.                 (char_u *)NULL, PV_NONE,
  1151.                 {(char_u *)0L, (char_u *)0L}
  1152. #endif
  1153.                 },
  1154.     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
  1155.                 (char_u *)&p_is, PV_NONE,
  1156.                 {(char_u *)FALSE, (char_u *)0L}},
  1157.     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
  1158. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  1159.                 (char_u *)&p_inde, PV_INDE,
  1160.                 {(char_u *)"", (char_u *)0L}
  1161. #else
  1162.                 (char_u *)NULL, PV_NONE,
  1163.                 {(char_u *)0L, (char_u *)0L}
  1164. #endif
  1165.                 },
  1166.     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  1167. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  1168.                 (char_u *)&p_indk, PV_INDK,
  1169.                 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
  1170. #else
  1171.                 (char_u *)NULL, PV_NONE,
  1172.                 {(char_u *)0L, (char_u *)0L}
  1173. #endif
  1174.                 },
  1175.     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
  1176.                 (char_u *)&p_inf, PV_INF,
  1177.                 {(char_u *)FALSE, (char_u *)0L}},
  1178.     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
  1179.                 (char_u *)&p_im, PV_NONE,
  1180.                 {(char_u *)FALSE, (char_u *)0L}},
  1181.     {"isfname",        "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1182.                 (char_u *)&p_isf, PV_NONE,
  1183.                 {
  1184. #ifdef BACKSLASH_IN_FILENAME
  1185.                 /* Excluded are: & and ^ are special in cmd.exe
  1186.                  * ( and ) are used in text separating fnames */
  1187.                 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
  1188. #else
  1189. # ifdef AMIGA
  1190.                 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
  1191. # else
  1192. #  ifdef VMS
  1193.                 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
  1194. #  else /* UNIX et al. */
  1195. #   ifdef EBCDIC
  1196.                 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
  1197. #   else
  1198.                 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
  1199. #   endif
  1200. #  endif
  1201. # endif
  1202. #endif
  1203.                 (char_u *)0L}},
  1204.     {"isident",        "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1205.                 (char_u *)&p_isi, PV_NONE,
  1206.                 {
  1207. #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  1208.                 (char_u *)"@,48-57,_,128-167,224-235",
  1209. #else
  1210. # ifdef EBCDIC
  1211.                 /* TODO: EBCDIC Check this! @ == isalpha()*/
  1212.                 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
  1213.                     "112-120,128,140-142,156,158,172,"
  1214.                     "174,186,191,203-207,219-225,235-239,"
  1215.                     "251-254",
  1216. # else
  1217.                 (char_u *)"@,48-57,_,192-255",
  1218. # endif
  1219. #endif
  1220.                 (char_u *)0L}},
  1221.     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
  1222.                 (char_u *)&p_isk, PV_ISK,
  1223.                 {
  1224. #ifdef EBCDIC
  1225.                  (char_u *)"@,240-249,_",
  1226.                  /* TODO: EBCDIC Check this! @ == isalpha()*/
  1227.                  (char_u *)"@,240-249,_,66-73,81-89,98-105,"
  1228.                     "112-120,128,140-142,156,158,172,"
  1229.                     "174,186,191,203-207,219-225,235-239,"
  1230.                     "251-254",
  1231. #else
  1232.                 (char_u *)"@,48-57,_",
  1233. # if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  1234.                 (char_u *)"@,48-57,_,128-167,224-235"
  1235. # else
  1236.                 (char_u *)"@,48-57,_,192-255"
  1237. # endif
  1238. #endif
  1239.                 }},
  1240.     {"isprint",        "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
  1241.                 (char_u *)&p_isp, PV_NONE,
  1242.                 {
  1243. #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
  1244.         || defined(VMS)
  1245.                 (char_u *)"@,~-255",
  1246. #else
  1247. # ifdef EBCDIC
  1248.                 /* all chars above 63 are printable */
  1249.                 (char_u *)"63-255",
  1250. # else
  1251.                 (char_u *)"@,161-255",
  1252. # endif
  1253. #endif
  1254.                 (char_u *)0L}},
  1255.     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
  1256.                 (char_u *)&p_js, PV_NONE,
  1257.                 {(char_u *)TRUE, (char_u *)0L}},
  1258.     {"key",        NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
  1259. #ifdef FEAT_CRYPT
  1260.                 (char_u *)&p_key, PV_KEY,
  1261.                 {(char_u *)"", (char_u *)0L}
  1262. #else
  1263.                 (char_u *)NULL, PV_NONE,
  1264.                 {(char_u *)0L, (char_u *)0L}
  1265. #endif
  1266.                 },
  1267.     {"keymap",        "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT,
  1268. #ifdef FEAT_KEYMAP
  1269.                 (char_u *)&p_keymap, PV_KMAP,
  1270.                 {(char_u *)"", (char_u *)0L}
  1271. #else
  1272.                 (char_u *)NULL, PV_NONE,
  1273.                 {(char_u *)"", (char_u *)0L}
  1274. #endif
  1275.     },
  1276.     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1277. #ifdef FEAT_VISUAL
  1278.                 (char_u *)&p_km, PV_NONE,
  1279. #else
  1280.                 (char_u *)NULL, PV_NONE,
  1281. #endif
  1282.                 {(char_u *)"", (char_u *)0L}},
  1283.     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1284.                 (char_u *)&p_kp, OPT_BOTH(PV_KP),
  1285.                 {
  1286. #if defined(MSDOS) || defined(MSWIN)
  1287.                 (char_u *)":help",
  1288. #else
  1289. #ifdef VMS
  1290.                 (char_u *)"help",
  1291. #else
  1292. # if defined(OS2)
  1293.                 (char_u *)"view /",
  1294. # else
  1295. #  ifdef USEMAN_S
  1296.                 (char_u *)"man -s",
  1297. #  else
  1298.                 (char_u *)"man",
  1299. #  endif
  1300. # endif
  1301. #endif
  1302. #endif
  1303.                 (char_u *)0L}},
  1304.     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1305. #ifdef FEAT_LANGMAP
  1306.                 (char_u *)&p_langmap, PV_NONE,
  1307.                 {(char_u *)"",    /* unmatched } */
  1308. #else
  1309.                 (char_u *)NULL, PV_NONE,
  1310.                 {(char_u *)NULL,
  1311. #endif
  1312.                 (char_u *)0L}},
  1313.     {"langmenu",    "lm",   P_STRING|P_VI_DEF,
  1314. #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
  1315.                 (char_u *)&p_lm, PV_NONE,
  1316. #else
  1317.                 (char_u *)NULL, PV_NONE,
  1318. #endif
  1319.                 {(char_u *)"", (char_u *)0L}},
  1320.     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
  1321. #ifdef FEAT_WINDOWS
  1322.                 (char_u *)&p_ls, PV_NONE,
  1323. #else
  1324.                 (char_u *)NULL, PV_NONE,
  1325. #endif
  1326.                 {(char_u *)1L, (char_u *)0L}},
  1327.     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
  1328.                 (char_u *)&p_lz, PV_NONE,
  1329.                 {(char_u *)FALSE, (char_u *)0L}},
  1330.     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
  1331. #ifdef FEAT_LINEBREAK
  1332.                 (char_u *)VAR_WIN, PV_LBR,
  1333. #else
  1334.                 (char_u *)NULL, PV_NONE,
  1335. #endif
  1336.                 {(char_u *)FALSE, (char_u *)0L}},
  1337.     {"lines",        NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
  1338.                 (char_u *)&Rows, PV_NONE,
  1339.                 {
  1340. #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
  1341.                 (char_u *)25L,
  1342. #else
  1343.                 (char_u *)24L,
  1344. #endif
  1345.                         (char_u *)0L}},
  1346.     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
  1347. #ifdef FEAT_GUI
  1348.                 (char_u *)&p_linespace, PV_NONE,
  1349. #else
  1350.                 (char_u *)NULL, PV_NONE,
  1351. #endif
  1352. #ifdef FEAT_GUI_W32
  1353.                 {(char_u *)1L, (char_u *)0L}
  1354. #else
  1355.                 {(char_u *)0L, (char_u *)0L}
  1356. #endif
  1357.                 },
  1358.     {"lisp",        NULL,   P_BOOL|P_VI_DEF,
  1359. #ifdef FEAT_LISP
  1360.                 (char_u *)&p_lisp, PV_LISP,
  1361. #else
  1362.                 (char_u *)NULL, PV_NONE,
  1363. #endif
  1364.                 {(char_u *)FALSE, (char_u *)0L}},
  1365.     {"lispwords",   "lw",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1366. #ifdef FEAT_LISP
  1367.                 (char_u *)&p_lispwords, PV_NONE,
  1368.                 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
  1369. #else
  1370.                 (char_u *)NULL, PV_NONE,
  1371.                 {(char_u *)"", (char_u *)0L}
  1372. #endif
  1373.                 },
  1374.     {"list",        NULL,   P_BOOL|P_VI_DEF|P_RWIN,
  1375.                 (char_u *)VAR_WIN, PV_LIST,
  1376.                 {(char_u *)FALSE, (char_u *)0L}},
  1377.     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
  1378.                 (char_u *)&p_lcs, PV_NONE,
  1379.                 {(char_u *)"eol:$", (char_u *)0L}},
  1380.     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
  1381.                 (char_u *)&p_lpl, PV_NONE,
  1382.                 {(char_u *)TRUE, (char_u *)0L}},
  1383.     {"magic",        NULL,   P_BOOL|P_VI_DEF,
  1384.                 (char_u *)&p_magic, PV_NONE,
  1385.                 {(char_u *)TRUE, (char_u *)0L}},
  1386.     {"makeef",        "mef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1387. #ifdef FEAT_QUICKFIX
  1388.                 (char_u *)&p_mef, PV_NONE,
  1389.                 {(char_u *)"", (char_u *)0L}
  1390. #else
  1391.                 (char_u *)NULL, PV_NONE,
  1392.                 {(char_u *)NULL, (char_u *)0L}
  1393. #endif
  1394.                 },
  1395.     {"makeprg",        "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1396. #ifdef FEAT_QUICKFIX
  1397.                 (char_u *)&p_mp, OPT_BOTH(PV_MP),
  1398. # ifdef VMS
  1399.                 {(char_u *)"MMS", (char_u *)0L}
  1400. # else
  1401.                 {(char_u *)"make", (char_u *)0L}
  1402. # endif
  1403. #else
  1404.                 (char_u *)NULL, PV_NONE,
  1405.                 {(char_u *)NULL, (char_u *)0L}
  1406. #endif
  1407.                 },
  1408.     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  1409.                 (char_u *)&p_mps, PV_MPS,
  1410.                 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
  1411.     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
  1412.                 (char_u *)&p_mat, PV_NONE,
  1413.                 {(char_u *)5L, (char_u *)0L}},
  1414.     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
  1415. #ifdef FEAT_EVAL
  1416.                 (char_u *)&p_mfd, PV_NONE,
  1417. #else
  1418.                 (char_u *)NULL, PV_NONE,
  1419. #endif
  1420.                 {(char_u *)100L, (char_u *)0L}},
  1421.     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
  1422.                 (char_u *)&p_mmd, PV_NONE,
  1423.                 {(char_u *)1000L, (char_u *)0L}},
  1424.     {"maxmem",        "mm",   P_NUM|P_VI_DEF,
  1425.                 (char_u *)&p_mm, PV_NONE,
  1426.                 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
  1427.     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
  1428.                 (char_u *)&p_mmt, PV_NONE,
  1429.                 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
  1430.     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
  1431. #ifdef FEAT_MENU
  1432.                 (char_u *)&p_mis, PV_NONE,
  1433. #else
  1434.                 (char_u *)NULL, PV_NONE,
  1435. #endif
  1436.                 {(char_u *)25L, (char_u *)0L}},
  1437.     {"mesg",        NULL,   P_BOOL|P_VI_DEF,
  1438.                 (char_u *)NULL, PV_NONE,
  1439.                 {(char_u *)FALSE, (char_u *)0L}},
  1440.     {"modeline",    "ml",   P_BOOL|P_VIM,
  1441.                 (char_u *)&p_ml, PV_ML,
  1442.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1443.     {"modelines",   "mls",  P_NUM|P_VI_DEF,
  1444.                 (char_u *)&p_mls, PV_NONE,
  1445.                 {(char_u *)5L, (char_u *)0L}},
  1446.     {"modifiable",  "ma",   P_BOOL|P_VI_DEF,
  1447.                 (char_u *)&p_ma, PV_MA,
  1448.                 {(char_u *)TRUE, (char_u *)0L}},
  1449.     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
  1450.                 (char_u *)&p_mod, PV_MOD,
  1451.                 {(char_u *)FALSE, (char_u *)0L}},
  1452.     {"more",        NULL,   P_BOOL|P_VIM,
  1453.                 (char_u *)&p_more, PV_NONE,
  1454.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1455.     {"mouse",        NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
  1456.                 (char_u *)&p_mouse, PV_NONE,
  1457.                 {
  1458. #if defined(MSDOS) || defined(WIN3264)
  1459.                 (char_u *)"a",
  1460. #else
  1461.                 (char_u *)"",
  1462. #endif
  1463.                 (char_u *)0L}},
  1464.     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
  1465. #ifdef FEAT_GUI
  1466.                 (char_u *)&p_mousef, PV_NONE,
  1467. #else
  1468.                 (char_u *)NULL, PV_NONE,
  1469. #endif
  1470.                 {(char_u *)FALSE, (char_u *)0L}},
  1471.     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
  1472. #ifdef FEAT_GUI
  1473.                 (char_u *)&p_mh, PV_NONE,
  1474. #else
  1475.                 (char_u *)NULL, PV_NONE,
  1476. #endif
  1477.                 {(char_u *)TRUE, (char_u *)0L}},
  1478.     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
  1479.                 (char_u *)&p_mousem, PV_NONE,
  1480.                 {
  1481. #if defined(MSDOS) || defined(MSWIN)
  1482.                 (char_u *)"popup",
  1483. #else
  1484. # if defined(MACOS)
  1485.                 (char_u *)"popup_setpos",
  1486. # else
  1487.                 (char_u *)"extend",
  1488. # endif
  1489. #endif
  1490.                 (char_u *)0L}},
  1491.     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1492. #ifdef FEAT_MOUSESHAPE
  1493.                 (char_u *)&p_mouseshape, PV_NONE,
  1494.                 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
  1495. #else
  1496.                 (char_u *)NULL, PV_NONE,
  1497.                 {(char_u *)NULL, (char_u *)0L}
  1498. #endif
  1499.                 },
  1500.     {"mousetime",   "mouset",    P_NUM|P_VI_DEF,
  1501.                 (char_u *)&p_mouset, PV_NONE,
  1502.                 {(char_u *)500L, (char_u *)0L}},
  1503.     {"novice",        NULL,   P_BOOL|P_VI_DEF,
  1504.                 (char_u *)NULL, PV_NONE,
  1505.                 {(char_u *)FALSE, (char_u *)0L}},
  1506.     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  1507.                 (char_u *)&p_nf, PV_NF,
  1508.                 {(char_u *)"octal,hex", (char_u *)0L}},
  1509.     {"number",        "nu",   P_BOOL|P_VI_DEF|P_RWIN,
  1510.                 (char_u *)VAR_WIN, PV_NU,
  1511.                 {(char_u *)FALSE, (char_u *)0L}},
  1512.     {"open",        NULL,   P_BOOL|P_VI_DEF,
  1513.                 (char_u *)NULL, PV_NONE,
  1514.                 {(char_u *)FALSE, (char_u *)0L}},
  1515.     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
  1516.                 (char_u *)NULL, PV_NONE,
  1517.                 {(char_u *)FALSE, (char_u *)0L}},
  1518.     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
  1519. #ifdef FEAT_OSFILETYPE
  1520.                 (char_u *)&p_oft, PV_OFT,
  1521.                 {(char_u *)DFLT_OFT, (char_u *)0L}
  1522. #else
  1523.                 (char_u *)NULL, PV_NONE,
  1524.                 {(char_u *)0L, (char_u *)0L}
  1525. #endif
  1526.                 },
  1527.     {"paragraphs",  "para", P_STRING|P_VI_DEF,
  1528.                 (char_u *)&p_para, PV_NONE,
  1529.                 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
  1530.     {"paste",        NULL,   P_BOOL|P_VI_DEF,
  1531.                 (char_u *)&p_paste, PV_NONE,
  1532.                 {(char_u *)FALSE, (char_u *)0L}},
  1533.     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
  1534.                 (char_u *)&p_pt, PV_NONE,
  1535.                 {(char_u *)"", (char_u *)0L}},
  1536.     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
  1537. #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
  1538.                 (char_u *)&p_pex, PV_NONE,
  1539.                 {(char_u *)"", (char_u *)0L}
  1540. #else
  1541.                 (char_u *)NULL, PV_NONE,
  1542.                 {(char_u *)0L, (char_u *)0L}
  1543. #endif
  1544.                 },
  1545.     {"patchmode",   "pm",   P_STRING|P_VI_DEF,
  1546.                 (char_u *)&p_pm, PV_NONE,
  1547.                 {(char_u *)"", (char_u *)0L}},
  1548.     {"path",        "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  1549.                 (char_u *)&p_path, OPT_BOTH(PV_PATH),
  1550.                 {
  1551. #if defined AMIGA || defined MSDOS || defined MSWIN
  1552.                 (char_u *)".,,",
  1553. #else
  1554. # if defined(__EMX__)
  1555.                 (char_u *)".,/emx/include,,",
  1556. # else /* Unix, probably */
  1557.                 (char_u *)".,/usr/include,,",
  1558. # endif
  1559. #endif
  1560.                 (char_u *)0L}},
  1561.     {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
  1562.                 (char_u *)&p_pi, PV_PI,
  1563.                 {(char_u *)FALSE, (char_u *)0L}},
  1564.     {"previewheight", "pvh",P_NUM|P_VI_DEF,
  1565. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  1566.                 (char_u *)&p_pvh, PV_NONE,
  1567. #else
  1568.                 (char_u *)NULL, PV_NONE,
  1569. #endif
  1570.                 {(char_u *)12L, (char_u *)0L}},
  1571.     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT,
  1572. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  1573.                 (char_u *)VAR_WIN, PV_PVW,
  1574. #else
  1575.                 (char_u *)NULL, PV_NONE,
  1576. #endif
  1577.                 {(char_u *)FALSE, (char_u *)0L}},
  1578.     {"printdevice", "pdev", P_STRING|P_VI_DEF,
  1579. #ifdef FEAT_PRINTER
  1580.                 (char_u *)&p_pdev, PV_NONE,
  1581.                 {(char_u *)"", (char_u *)0L}
  1582. #else
  1583.                 (char_u *)NULL, PV_NONE,
  1584.                 {(char_u *)NULL, (char_u *)0L}
  1585. #endif
  1586.                 },
  1587.     {"printencoding", "penc", P_STRING|P_VI_DEF,
  1588. #ifdef FEAT_POSTSCRIPT
  1589.                 (char_u *)&p_penc, PV_NONE,
  1590.                 {(char_u *)"", (char_u *)0L}
  1591. #else
  1592.                 (char_u *)NULL, PV_NONE,
  1593.                 {(char_u *)NULL, (char_u *)0L}
  1594. #endif
  1595.                 },
  1596.     {"printexpr", "pexpr",  P_STRING|P_VI_DEF,
  1597. #ifdef FEAT_POSTSCRIPT
  1598.                 (char_u *)&p_pexpr, PV_NONE,
  1599.                 {(char_u *)"", (char_u *)0L}
  1600. #else
  1601.                 (char_u *)NULL, PV_NONE,
  1602.                 {(char_u *)NULL, (char_u *)0L}
  1603. #endif
  1604.                 },
  1605.     {"printfont", "pfn",    P_STRING|P_VI_DEF,
  1606. #ifdef FEAT_PRINTER
  1607.                 (char_u *)&p_pfn, PV_NONE,
  1608.                 {
  1609. # ifdef MSWIN
  1610.                 (char_u *)"Courier_New:h10",
  1611. # else
  1612.                 (char_u *)"courier",
  1613. # endif
  1614.                 (char_u *)0L}
  1615. #else
  1616.                 (char_u *)NULL, PV_NONE,
  1617.                 {(char_u *)NULL, (char_u *)0L}
  1618. #endif
  1619.                 },
  1620.     {"printheader", "pheader",  P_STRING|P_VI_DEF|P_GETTEXT,
  1621. #ifdef FEAT_PRINTER
  1622.                 (char_u *)&p_header, PV_NONE,
  1623.                 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
  1624. #else
  1625.                 (char_u *)NULL, PV_NONE,
  1626.                 {(char_u *)NULL, (char_u *)0L}
  1627. #endif
  1628.                 },
  1629.     {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1630. #ifdef FEAT_PRINTER
  1631.                 (char_u *)&p_popt, 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.     {"prompt",        NULL,   P_BOOL|P_VI_DEF,
  1639.                 (char_u *)NULL, PV_NONE,
  1640.                 {(char_u *)FALSE, (char_u *)0L}},
  1641.     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT,
  1642.                 (char_u *)&p_ro, PV_RO,
  1643.                 {(char_u *)FALSE, (char_u *)0L}},
  1644.     {"redraw",        NULL,   P_BOOL|P_VI_DEF,
  1645.                 (char_u *)NULL, PV_NONE,
  1646.                 {(char_u *)FALSE, (char_u *)0L}},
  1647.     {"remap",        NULL,   P_BOOL|P_VI_DEF,
  1648.                 (char_u *)&p_remap, PV_NONE,
  1649.                 {(char_u *)TRUE, (char_u *)0L}},
  1650.     {"report",        NULL,   P_NUM|P_VI_DEF,
  1651.                 (char_u *)&p_report, PV_NONE,
  1652.                 {(char_u *)2L, (char_u *)0L}},
  1653.     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
  1654. #ifdef WIN3264
  1655.                 (char_u *)&p_rs, PV_NONE,
  1656. #else
  1657.                 (char_u *)NULL, PV_NONE,
  1658. #endif
  1659.                 {(char_u *)TRUE, (char_u *)0L}},
  1660.     {"revins",        "ri",   P_BOOL|P_VI_DEF|P_VIM,
  1661. #ifdef FEAT_RIGHTLEFT
  1662.                 (char_u *)&p_ri, PV_NONE,
  1663. #else
  1664.                 (char_u *)NULL, PV_NONE,
  1665. #endif
  1666.                 {(char_u *)FALSE, (char_u *)0L}},
  1667.     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
  1668. #ifdef FEAT_RIGHTLEFT
  1669.                 (char_u *)VAR_WIN, PV_RL,
  1670. #else
  1671.                 (char_u *)NULL, PV_NONE,
  1672. #endif
  1673.                 {(char_u *)FALSE, (char_u *)0L}},
  1674.     {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
  1675. #ifdef FEAT_RIGHTLEFT
  1676.                 (char_u *)VAR_WIN, PV_RLC,
  1677.                 {(char_u *)"search", (char_u *)NULL}
  1678. #else
  1679.                 (char_u *)NULL, PV_NONE,
  1680.                 {(char_u *)NULL, (char_u *)0L}
  1681. #endif
  1682.                 },
  1683.     {"ruler",        "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
  1684. #ifdef FEAT_CMDL_INFO
  1685.                 (char_u *)&p_ru, PV_NONE,
  1686. #else
  1687.                 (char_u *)NULL, PV_NONE,
  1688. #endif
  1689.                 {(char_u *)FALSE, (char_u *)0L}},
  1690.     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
  1691. #ifdef FEAT_STL_OPT
  1692.                 (char_u *)&p_ruf, PV_NONE,
  1693. #else
  1694.                 (char_u *)NULL, PV_NONE,
  1695. #endif
  1696.                 {(char_u *)"", (char_u *)0L}},
  1697.     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
  1698.                 (char_u *)&p_rtp, PV_NONE,
  1699.                 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
  1700.     {"scroll",        "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
  1701.                 (char_u *)VAR_WIN, PV_SCROLL,
  1702.                 {(char_u *)12L, (char_u *)0L}},
  1703.     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
  1704. #ifdef FEAT_SCROLLBIND
  1705.                 (char_u *)VAR_WIN, PV_SCBIND,
  1706. #else
  1707.                 (char_u *)NULL, PV_NONE,
  1708. #endif
  1709.                 {(char_u *)FALSE, (char_u *)0L}},
  1710.     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
  1711.                 (char_u *)&p_sj, PV_NONE,
  1712.                 {(char_u *)1L, (char_u *)0L}},
  1713.     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
  1714.                 (char_u *)&p_so, PV_NONE,
  1715.                 {(char_u *)0L, (char_u *)0L}},
  1716.     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1717. #ifdef FEAT_SCROLLBIND
  1718.                 (char_u *)&p_sbo, PV_NONE,
  1719.                 {(char_u *)"ver,jump", (char_u *)0L}
  1720. #else
  1721.                 (char_u *)NULL, PV_NONE,
  1722.                 {(char_u *)0L, (char_u *)0L}
  1723. #endif
  1724.                 },
  1725.     {"sections",    "sect", P_STRING|P_VI_DEF,
  1726.                 (char_u *)&p_sections, PV_NONE,
  1727.                 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
  1728.     {"secure",        NULL,   P_BOOL|P_VI_DEF|P_SECURE,
  1729.                 (char_u *)&p_secure, PV_NONE,
  1730.                 {(char_u *)FALSE, (char_u *)0L}},
  1731.     {"selection",   "sel",  P_STRING|P_VI_DEF,
  1732. #ifdef FEAT_VISUAL
  1733.                 (char_u *)&p_sel, PV_NONE,
  1734. #else
  1735.                 (char_u *)NULL, PV_NONE,
  1736. #endif
  1737.                 {(char_u *)"inclusive", (char_u *)0L}},
  1738.     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1739. #ifdef FEAT_VISUAL
  1740.                 (char_u *)&p_slm, PV_NONE,
  1741. #else
  1742.                 (char_u *)NULL, PV_NONE,
  1743. #endif
  1744.                 {(char_u *)"", (char_u *)0L}},
  1745.     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1746. #ifdef FEAT_SESSION
  1747.                 (char_u *)&p_ssop, PV_NONE,
  1748.          {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
  1749.                                    (char_u *)0L}
  1750. #else
  1751.                 (char_u *)NULL, PV_NONE,
  1752.                 {(char_u *)0L, (char_u *)0L}
  1753. #endif
  1754.                 },
  1755.     {"shell",        "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1756.                 (char_u *)&p_sh, PV_NONE,
  1757.                 {
  1758. #ifdef VMS
  1759.                 (char_u *)"-",
  1760. #else
  1761. # if defined(MSDOS)
  1762.                 (char_u *)"command",
  1763. # else
  1764. #  if defined(WIN16)
  1765.                 (char_u *)"command.com",
  1766. #  else
  1767. #   if defined(WIN3264)
  1768.                 (char_u *)"",    /* set in set_init_1() */
  1769. #   else
  1770. #    if defined(OS2)
  1771.                 (char_u *)"cmd.exe",
  1772. #    else
  1773. #     if defined(ARCHIE)
  1774.                 (char_u *)"gos",
  1775. #     else
  1776.                 (char_u *)"sh",
  1777. #     endif
  1778. #    endif
  1779. #   endif
  1780. #  endif
  1781. # endif
  1782. #endif /* VMS */
  1783.                 (char_u *)0L}},
  1784.     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
  1785.                 (char_u *)&p_shcf, PV_NONE,
  1786.                 {
  1787. #if defined(MSDOS) || defined(MSWIN)
  1788.                 (char_u *)"/c",
  1789. #else
  1790. # if defined(OS2)
  1791.                 (char_u *)"/c",
  1792. # else
  1793.                 (char_u *)"-c",
  1794. # endif
  1795. #endif
  1796.                 (char_u *)0L}},
  1797.     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
  1798. #ifdef FEAT_QUICKFIX
  1799.                 (char_u *)&p_sp, PV_NONE,
  1800.                 {
  1801. #if defined(UNIX) || defined(OS2)
  1802. # ifdef ARCHIE
  1803.                 (char_u *)"2>",
  1804. # else
  1805.                 (char_u *)"| tee",
  1806. # endif
  1807. #else
  1808.                 (char_u *)">",
  1809. #endif
  1810.                 (char_u *)0L}
  1811. #else
  1812.                 (char_u *)NULL, PV_NONE,
  1813.                 {(char_u *)0L, (char_u *)0L}
  1814. #endif
  1815.     },
  1816.     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
  1817.                 (char_u *)&p_shq, PV_NONE,
  1818.                 {(char_u *)"", (char_u *)0L}},
  1819.     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
  1820.                 (char_u *)&p_srr, PV_NONE,
  1821.                 {(char_u *)">", (char_u *)0L}},
  1822.     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
  1823. #ifdef BACKSLASH_IN_FILENAME
  1824.                 (char_u *)&p_ssl, PV_NONE,
  1825. #else
  1826.                 (char_u *)NULL, PV_NONE,
  1827. #endif
  1828.                 {(char_u *)FALSE, (char_u *)0L}},
  1829.     {"shelltype",   "st",   P_NUM|P_VI_DEF,
  1830. #ifdef AMIGA
  1831.                 (char_u *)&p_st, PV_NONE,
  1832. #else
  1833.                 (char_u *)NULL, PV_NONE,
  1834. #endif
  1835.                 {(char_u *)0L, (char_u *)0L}},
  1836.     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
  1837.                 (char_u *)&p_sxq, PV_NONE,
  1838.                 {
  1839. #if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
  1840.                 (char_u *)"\"",
  1841. #else
  1842.                 (char_u *)"",
  1843. #endif
  1844.                 (char_u *)0L}},
  1845.     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
  1846.                 (char_u *)&p_sr, PV_NONE,
  1847.                 {(char_u *)FALSE, (char_u *)0L}},
  1848.     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
  1849.                 (char_u *)&p_sw, PV_SW,
  1850.                 {(char_u *)8L, (char_u *)0L}},
  1851.     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
  1852.                 (char_u *)&p_shm, PV_NONE,
  1853.                 {(char_u *)"", (char_u *)"filnxtToO"}},
  1854.     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
  1855. #ifdef SHORT_FNAME
  1856.                 (char_u *)NULL, PV_NONE,
  1857. #else
  1858.                 (char_u *)&p_sn, PV_SN,
  1859. #endif
  1860.                 {(char_u *)FALSE, (char_u *)0L}},
  1861.     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
  1862. #ifdef FEAT_LINEBREAK
  1863.                 (char_u *)&p_sbr, PV_NONE,
  1864. #else
  1865.                 (char_u *)NULL, PV_NONE,
  1866. #endif
  1867.                 {(char_u *)"", (char_u *)0L}},
  1868.     {"showcmd",        "sc",   P_BOOL|P_VIM,
  1869. #ifdef FEAT_CMDL_INFO
  1870.                 (char_u *)&p_sc, PV_NONE,
  1871. #else
  1872.                 (char_u *)NULL, PV_NONE,
  1873. #endif
  1874.                 {(char_u *)FALSE,
  1875. #ifdef UNIX
  1876.                 (char_u *)FALSE
  1877. #else
  1878.                 (char_u *)TRUE
  1879. #endif
  1880.                 }},
  1881.     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
  1882.                 (char_u *)&p_sft, PV_NONE,
  1883.                 {(char_u *)FALSE, (char_u *)0L}},
  1884.     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
  1885.                 (char_u *)&p_sm, PV_NONE,
  1886.                 {(char_u *)FALSE, (char_u *)0L}},
  1887.     {"showmode",    "smd",  P_BOOL|P_VIM,
  1888.                 (char_u *)&p_smd, PV_NONE,
  1889.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1890.     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
  1891.                 (char_u *)&p_ss, PV_NONE,
  1892.                 {(char_u *)0L, (char_u *)0L}},
  1893.     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
  1894.                 (char_u *)&p_siso, PV_NONE,
  1895.                 {(char_u *)0L, (char_u *)0L}},
  1896.     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
  1897.                 (char_u *)NULL, PV_NONE,
  1898.                 {(char_u *)FALSE, (char_u *)0L}},
  1899.     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
  1900.                 (char_u *)&p_scs, PV_NONE,
  1901.                 {(char_u *)FALSE, (char_u *)0L}},
  1902.     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
  1903. #ifdef FEAT_SMARTINDENT
  1904.                 (char_u *)&p_si, PV_SI,
  1905. #else
  1906.                 (char_u *)NULL, PV_NONE,
  1907. #endif
  1908.                 {(char_u *)FALSE, (char_u *)0L}},
  1909.     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
  1910.                 (char_u *)&p_sta, PV_NONE,
  1911.                 {(char_u *)FALSE, (char_u *)0L}},
  1912.     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
  1913.                 (char_u *)&p_sts, PV_STS,
  1914.                 {(char_u *)0L, (char_u *)0L}},
  1915.     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
  1916.                 (char_u *)NULL, PV_NONE,
  1917.                 {(char_u *)FALSE, (char_u *)0L}},
  1918.     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
  1919. #ifdef FEAT_WINDOWS
  1920.                 (char_u *)&p_sb, PV_NONE,
  1921. #else
  1922.                 (char_u *)NULL, PV_NONE,
  1923. #endif
  1924.                 {(char_u *)FALSE, (char_u *)0L}},
  1925.     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
  1926. #ifdef FEAT_VERTSPLIT
  1927.                 (char_u *)&p_spr, PV_NONE,
  1928. #else
  1929.                 (char_u *)NULL, PV_NONE,
  1930. #endif
  1931.                 {(char_u *)FALSE, (char_u *)0L}},
  1932.     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
  1933.                 (char_u *)&p_sol, PV_NONE,
  1934.                 {(char_u *)TRUE, (char_u *)0L}},
  1935.     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
  1936. #ifdef FEAT_STL_OPT
  1937.                 (char_u *)&p_stl, PV_NONE,
  1938. #else
  1939.                 (char_u *)NULL, PV_NONE,
  1940. #endif
  1941.                 {(char_u *)"", (char_u *)0L}},
  1942.     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1943.                 (char_u *)&p_su, PV_NONE,
  1944.                 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
  1945.                 (char_u *)0L}},
  1946.     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
  1947. #if defined(FEAT_SEARCHPATH)
  1948.                 (char_u *)&p_sua, PV_SUA,
  1949.                 {(char_u *)"", (char_u *)0L}
  1950. #else
  1951.                 (char_u *)NULL, PV_NONE,
  1952.                 {(char_u *)0L, (char_u *)0L}
  1953. #endif
  1954.                 },
  1955.     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
  1956.                 (char_u *)&p_swf, PV_SWF,
  1957.                 {(char_u *)TRUE, (char_u *)0L}},
  1958.     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
  1959.                 (char_u *)&p_sws, PV_NONE,
  1960.                 {(char_u *)"fsync", (char_u *)0L}},
  1961.     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1962.                 (char_u *)&p_swb, PV_NONE,
  1963.                 {(char_u *)"", (char_u *)0L}},
  1964.     {"syntax",        "syn",  P_STRING|P_ALLOCED|P_VI_DEF,
  1965. #ifdef FEAT_SYN_HL
  1966.                 (char_u *)&p_syn, PV_SYN,
  1967.                 {(char_u *)"", (char_u *)0L}
  1968. #else
  1969.                 (char_u *)NULL, PV_NONE,
  1970.                 {(char_u *)0L, (char_u *)0L}
  1971. #endif
  1972.                 },
  1973.     {"tabstop",        "ts",   P_NUM|P_VI_DEF|P_RBUF,
  1974.                 (char_u *)&p_ts, PV_TS,
  1975.                 {(char_u *)8L, (char_u *)0L}},
  1976.     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
  1977.                 (char_u *)&p_tbs, PV_NONE,
  1978. #ifdef VMS    /* binary searching doesn't appear to work on VMS */
  1979.                 {(char_u *)0L, (char_u *)0L}
  1980. #else
  1981.                 {(char_u *)TRUE, (char_u *)0L}
  1982. #endif
  1983.                 },
  1984.     {"taglength",   "tl",   P_NUM|P_VI_DEF,
  1985.                 (char_u *)&p_tl, PV_NONE,
  1986.                 {(char_u *)0L, (char_u *)0L}},
  1987.     {"tagrelative", "tr",   P_BOOL|P_VIM,
  1988.                 (char_u *)&p_tr, PV_NONE,
  1989.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1990.     {"tags",        "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  1991.                 (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
  1992.                 {
  1993. #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
  1994.                 (char_u *)"./tags,./TAGS,tags,TAGS",
  1995. #else
  1996.                 (char_u *)"./tags,tags",
  1997. #endif
  1998.                 (char_u *)0L}},
  1999.     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
  2000.                 (char_u *)&p_tgst, PV_NONE,
  2001.                 {(char_u *)TRUE, (char_u *)0L}},
  2002.     {"term",        NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
  2003.                 (char_u *)&T_NAME, PV_NONE,
  2004.                 {(char_u *)"", (char_u *)0L}},
  2005.     {"termbidi", "tbidi",   P_BOOL|P_VI_DEF,
  2006. #ifdef FEAT_ARABIC
  2007.                 (char_u *)&p_tbidi, PV_NONE,
  2008. #else
  2009.                 (char_u *)NULL, PV_NONE,
  2010. #endif
  2011.                 {(char_u *)FALSE, (char_u *)0L}},
  2012.     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
  2013. #ifdef FEAT_MBYTE
  2014.                 (char_u *)&p_tenc, PV_NONE,
  2015.                 {(char_u *)"", (char_u *)0L}
  2016. #else
  2017.                 (char_u *)NULL, PV_NONE,
  2018.                 {(char_u *)0L, (char_u *)0L}
  2019. #endif
  2020.                 },
  2021.     {"terse",        NULL,   P_BOOL|P_VI_DEF,
  2022.                 (char_u *)&p_terse, PV_NONE,
  2023.                 {(char_u *)FALSE, (char_u *)0L}},
  2024.     {"textauto",    "ta",   P_BOOL|P_VIM,
  2025.                 (char_u *)&p_ta, PV_NONE,
  2026.                 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
  2027.     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
  2028.                 (char_u *)&p_tx, PV_TX,
  2029.                 {
  2030. #ifdef USE_CRNL
  2031.                 (char_u *)TRUE,
  2032. #else
  2033.                 (char_u *)FALSE,
  2034. #endif
  2035.                 (char_u *)0L}},
  2036.     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM,
  2037.                 (char_u *)&p_tw, PV_TW,
  2038.                 {(char_u *)0L, (char_u *)0L}},
  2039.     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  2040. #ifdef FEAT_INS_EXPAND
  2041.                 (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
  2042. #else
  2043.                 (char_u *)NULL, PV_NONE,
  2044. #endif
  2045.                 {(char_u *)"", (char_u *)0L}},
  2046.     {"tildeop",        "top",  P_BOOL|P_VI_DEF|P_VIM,
  2047.                 (char_u *)&p_to, PV_NONE,
  2048.                 {(char_u *)FALSE, (char_u *)0L}},
  2049.     {"timeout",        "to",   P_BOOL|P_VI_DEF,
  2050.                 (char_u *)&p_timeout, PV_NONE,
  2051.                 {(char_u *)TRUE, (char_u *)0L}},
  2052.     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
  2053.                 (char_u *)&p_tm, PV_NONE,
  2054.                 {(char_u *)1000L, (char_u *)0L}},
  2055.     {"title",        NULL,   P_BOOL|P_VI_DEF,
  2056. #ifdef FEAT_TITLE
  2057.                 (char_u *)&p_title, PV_NONE,
  2058. #else
  2059.                 (char_u *)NULL, PV_NONE,
  2060. #endif
  2061.                 {(char_u *)FALSE, (char_u *)0L}},
  2062.     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
  2063. #ifdef FEAT_TITLE
  2064.                 (char_u *)&p_titlelen, PV_NONE,
  2065. #else
  2066.                 (char_u *)NULL, PV_NONE,
  2067. #endif
  2068.                 {(char_u *)85L, (char_u *)0L}},
  2069.     {"titleold",    NULL,   P_STRING|P_VI_DEF|P_GETTEXT,
  2070. #ifdef FEAT_TITLE
  2071.                 (char_u *)&p_titleold, PV_NONE,
  2072.                 {(char_u *)N_("Thanks for flying Vim"),
  2073.                                    (char_u *)0L}
  2074. #else
  2075.                 (char_u *)NULL, PV_NONE,
  2076.                 {(char_u *)0L, (char_u *)0L}
  2077. #endif
  2078.                 },
  2079.     {"titlestring", NULL,   P_STRING|P_VI_DEF,
  2080. #ifdef FEAT_TITLE
  2081.                 (char_u *)&p_titlestring, PV_NONE,
  2082. #else
  2083.                 (char_u *)NULL, PV_NONE,
  2084. #endif
  2085.                 {(char_u *)"", (char_u *)0L}},
  2086. #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
  2087.     {"toolbar",     "tb",   P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
  2088.                 (char_u *)&p_toolbar, PV_NONE,
  2089.                 {(char_u *)"icons,tooltips", (char_u *)0L}},
  2090. #endif
  2091. #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
  2092.     {"toolbariconsize",    "tbis", P_STRING|P_VI_DEF,
  2093.                 (char_u *)&p_tbis, PV_NONE,
  2094.                 {(char_u *)"small", (char_u *)0L}},
  2095. #endif
  2096.     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
  2097.                 (char_u *)&p_ttimeout, PV_NONE,
  2098.                 {(char_u *)FALSE, (char_u *)0L}},
  2099.     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
  2100.                 (char_u *)&p_ttm, PV_NONE,
  2101.                 {(char_u *)-1L, (char_u *)0L}},
  2102.     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
  2103.                 (char_u *)&p_tbi, PV_NONE,
  2104.                 {(char_u *)TRUE, (char_u *)0L}},
  2105.     {"ttyfast",        "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
  2106.                 (char_u *)&p_tf, PV_NONE,
  2107.                 {(char_u *)FALSE, (char_u *)0L}},
  2108.     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
  2109. #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
  2110.                 (char_u *)&p_ttym, PV_NONE,
  2111. #else
  2112.                 (char_u *)NULL, PV_NONE,
  2113. #endif
  2114.                 {(char_u *)"", (char_u *)0L}},
  2115.     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
  2116.                 (char_u *)&p_ttyscroll, PV_NONE,
  2117.                 {(char_u *)999L, (char_u *)0L}},
  2118.     {"ttytype",        "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
  2119.                 (char_u *)&T_NAME, PV_NONE,
  2120.                 {(char_u *)"", (char_u *)0L}},
  2121.     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
  2122.                 (char_u *)&p_ul, PV_NONE,
  2123.                 {
  2124. #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
  2125.                 (char_u *)1000L,
  2126. #else
  2127.                 (char_u *)100L,
  2128. #endif
  2129.                 (char_u *)0L}},
  2130.     {"updatecount", "uc",   P_NUM|P_VI_DEF,
  2131.                 (char_u *)&p_uc, PV_NONE,
  2132.                 {(char_u *)200L, (char_u *)0L}},
  2133.     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
  2134.                 (char_u *)&p_ut, PV_NONE,
  2135.                 {(char_u *)4000L, (char_u *)0L}},
  2136.     {"verbose",        "vbs",  P_NUM|P_VI_DEF,
  2137.                 (char_u *)&p_verbose, PV_NONE,
  2138.                 {(char_u *)0L, (char_u *)0L}},
  2139.     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  2140. #ifdef FEAT_SESSION
  2141.                 (char_u *)&p_vdir, PV_NONE,
  2142.                 {(char_u *)DFLT_VDIR, (char_u *)0L}
  2143. #else
  2144.                 (char_u *)NULL, PV_NONE,
  2145.                 {(char_u *)0L, (char_u *)0L}
  2146. #endif
  2147.                 },
  2148.     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  2149. #ifdef FEAT_SESSION
  2150.                 (char_u *)&p_vop, PV_NONE,
  2151.                 {(char_u *)"folds,options,cursor", (char_u *)0L}
  2152. #else
  2153.                 (char_u *)NULL, PV_NONE,
  2154.                 {(char_u *)0L, (char_u *)0L}
  2155. #endif
  2156.                 },
  2157.     {"viminfo",        "vi",   P_STRING|P_COMMA|P_NODUP|P_SECURE,
  2158. #ifdef FEAT_VIMINFO
  2159.                 (char_u *)&p_viminfo, PV_NONE,
  2160. #else
  2161.                 (char_u *)NULL, PV_NONE,
  2162. #endif
  2163. #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  2164.                 {(char_u *)"", (char_u *)"'20,\"50,h,rA:,rB:"}
  2165. #else
  2166. # ifdef AMIGA
  2167.                 {(char_u *)"",
  2168.                      (char_u *)"'20,\"50,h,rdf0:,rdf1:,rdf2:"}
  2169. # else
  2170.                 {(char_u *)"", (char_u *)"'20,\"50,h"}
  2171. # endif
  2172. #endif
  2173.     },
  2174.     {"virtualedit", "ve",   P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
  2175. #ifdef FEAT_VIRTUALEDIT
  2176.                 (char_u *)&p_ve, PV_NONE,
  2177.                 {(char_u *)"", (char_u *)""}
  2178. #else
  2179.                 (char_u *)NULL, PV_NONE,
  2180.                 {(char_u *)0L, (char_u *)0L}
  2181. #endif
  2182.                 },
  2183.     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
  2184.                 (char_u *)&p_vb, PV_NONE,
  2185.                 {(char_u *)FALSE, (char_u *)0L}},
  2186.     {"w300",        NULL,   P_NUM|P_VI_DEF,
  2187.                 (char_u *)NULL, PV_NONE,
  2188.                 {(char_u *)0L, (char_u *)0L}},
  2189.     {"w1200",        NULL,   P_NUM|P_VI_DEF,
  2190.                 (char_u *)NULL, PV_NONE,
  2191.                 {(char_u *)0L, (char_u *)0L}},
  2192.     {"w9600",        NULL,   P_NUM|P_VI_DEF,
  2193.                 (char_u *)NULL, PV_NONE,
  2194.                 {(char_u *)0L, (char_u *)0L}},
  2195.     {"warn",        NULL,   P_BOOL|P_VI_DEF,
  2196.                 (char_u *)&p_warn, PV_NONE,
  2197.                 {(char_u *)TRUE, (char_u *)0L}},
  2198.     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
  2199.                 (char_u *)&p_wiv, PV_NONE,
  2200.                 {(char_u *)FALSE, (char_u *)0L}},
  2201.     {"whichwrap",   "ww",   P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
  2202.                 (char_u *)&p_ww, PV_NONE,
  2203.                 {(char_u *)"", (char_u *)"b,s"}},
  2204.     {"wildchar",    "wc",   P_NUM|P_VIM,
  2205.                 (char_u *)&p_wc, PV_NONE,
  2206.                 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
  2207.     {"wildcharm",   "wcm",   P_NUM|P_VI_DEF,
  2208.                 (char_u *)&p_wcm, PV_NONE,
  2209.                 {(char_u *)0L, (char_u *)0L}},
  2210.     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  2211. #ifdef FEAT_WILDIGN
  2212.                 (char_u *)&p_wig, PV_NONE,
  2213. #else
  2214.                 (char_u *)NULL, PV_NONE,
  2215. #endif
  2216.                 {(char_u *)"", (char_u *)0L}},
  2217.     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
  2218. #ifdef FEAT_WILDMENU
  2219.                 (char_u *)&p_wmnu, PV_NONE,
  2220. #else
  2221.                 (char_u *)NULL, PV_NONE,
  2222. #endif
  2223.                 {(char_u *)FALSE, (char_u *)0L}},
  2224.     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  2225.                 (char_u *)&p_wim, PV_NONE,
  2226.                 {(char_u *)"full", (char_u *)0L}},
  2227.     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
  2228. #ifdef FEAT_WAK
  2229.                 (char_u *)&p_wak, PV_NONE,
  2230.                 {(char_u *)"menu", (char_u *)0L}
  2231. #else
  2232.                 (char_u *)NULL, PV_NONE,
  2233.                 {(char_u *)NULL, (char_u *)0L}
  2234. #endif
  2235.                 },
  2236.     {"window",        "wi",   P_NUM|P_VI_DEF,
  2237.                 (char_u *)NULL, PV_NONE,
  2238.                 {(char_u *)0L, (char_u *)0L}},
  2239.     {"winheight",   "wh",   P_NUM|P_VI_DEF,
  2240. #ifdef FEAT_WINDOWS
  2241.                 (char_u *)&p_wh, PV_NONE,
  2242. #else
  2243.                 (char_u *)NULL, PV_NONE,
  2244. #endif
  2245.                 {(char_u *)1L, (char_u *)0L}},
  2246.     {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
  2247. #if defined(FEAT_WINDOWS)
  2248.                 (char_u *)VAR_WIN, PV_WFH,
  2249. #else
  2250.                 (char_u *)NULL, PV_NONE,
  2251. #endif
  2252.                 {(char_u *)FALSE, (char_u *)0L}},
  2253.     {"winminheight", "wmh", P_NUM|P_VI_DEF,
  2254. #ifdef FEAT_WINDOWS
  2255.                 (char_u *)&p_wmh, PV_NONE,
  2256. #else
  2257.                 (char_u *)NULL, PV_NONE,
  2258. #endif
  2259.                 {(char_u *)1L, (char_u *)0L}},
  2260.     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
  2261. #ifdef FEAT_VERTSPLIT
  2262.                 (char_u *)&p_wmw, PV_NONE,
  2263. #else
  2264.                 (char_u *)NULL, PV_NONE,
  2265. #endif
  2266.                 {(char_u *)1L, (char_u *)0L}},
  2267.     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
  2268. #ifdef FEAT_VERTSPLIT
  2269.                 (char_u *)&p_wiw, PV_NONE,
  2270. #else
  2271.                 (char_u *)NULL, PV_NONE,
  2272. #endif
  2273.                 {(char_u *)20L, (char_u *)0L}},
  2274.     {"wrap",        NULL,   P_BOOL|P_VI_DEF|P_RWIN,
  2275.                 (char_u *)VAR_WIN, PV_WRAP,
  2276.                 {(char_u *)TRUE, (char_u *)0L}},
  2277.     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
  2278.                 (char_u *)&p_wm, PV_WM,
  2279.                 {(char_u *)0L, (char_u *)0L}},
  2280.     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
  2281.                 (char_u *)&p_ws, PV_NONE,
  2282.                 {(char_u *)TRUE, (char_u *)0L}},
  2283.     {"write",        NULL,   P_BOOL|P_VI_DEF,
  2284.                 (char_u *)&p_write, PV_NONE,
  2285.                 {(char_u *)TRUE, (char_u *)0L}},
  2286.     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
  2287.                 (char_u *)&p_wa, PV_NONE,
  2288.                 {(char_u *)FALSE, (char_u *)0L}},
  2289.     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
  2290.                 (char_u *)&p_wb, PV_NONE,
  2291.                 {
  2292. #ifdef FEAT_WRITEBACKUP
  2293.                 (char_u *)TRUE,
  2294. #else
  2295.                 (char_u *)FALSE,
  2296. #endif
  2297.                 (char_u *)0L}},
  2298.     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
  2299.                 (char_u *)&p_wd, PV_NONE,
  2300.                 {(char_u *)0L, (char_u *)0L}},
  2301.  
  2302. /* terminal output codes */
  2303. #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL, \
  2304.                 (char_u *)&vvv, PV_NONE, \
  2305.                 {(char_u *)"", (char_u *)0L}},
  2306.  
  2307.     p_term("t_AB", T_CAB)
  2308.     p_term("t_AF", T_CAF)
  2309.     p_term("t_AL", T_CAL)
  2310.     p_term("t_al", T_AL)
  2311.     p_term("t_bc", T_BC)
  2312.     p_term("t_cd", T_CD)
  2313.     p_term("t_ce", T_CE)
  2314.     p_term("t_cl", T_CL)
  2315.     p_term("t_cm", T_CM)
  2316.     p_term("t_Co", T_CCO)
  2317.     p_term("t_CS", T_CCS)
  2318.     p_term("t_cs", T_CS)
  2319. #ifdef FEAT_VERTSPLIT
  2320.     p_term("t_CV", T_CSV)
  2321. #endif
  2322.     p_term("t_ut", T_UT)
  2323.     p_term("t_da", T_DA)
  2324.     p_term("t_db", T_DB)
  2325.     p_term("t_DL", T_CDL)
  2326.     p_term("t_dl", T_DL)
  2327.     p_term("t_fs", T_FS)
  2328.     p_term("t_IE", T_CIE)
  2329.     p_term("t_IS", T_CIS)
  2330.     p_term("t_ke", T_KE)
  2331.     p_term("t_ks", T_KS)
  2332.     p_term("t_le", T_LE)
  2333.     p_term("t_mb", T_MB)
  2334.     p_term("t_md", T_MD)
  2335.     p_term("t_me", T_ME)
  2336.     p_term("t_mr", T_MR)
  2337.     p_term("t_ms", T_MS)
  2338.     p_term("t_nd", T_ND)
  2339.     p_term("t_op", T_OP)
  2340.     p_term("t_RI", T_CRI)
  2341.     p_term("t_RV", T_CRV)
  2342.     p_term("t_Sb", T_CSB)
  2343.     p_term("t_Sf", T_CSF)
  2344.     p_term("t_se", T_SE)
  2345.     p_term("t_so", T_SO)
  2346.     p_term("t_sr", T_SR)
  2347.     p_term("t_ts", T_TS)
  2348.     p_term("t_te", T_TE)
  2349.     p_term("t_ti", T_TI)
  2350.     p_term("t_ue", T_UE)
  2351.     p_term("t_us", T_US)
  2352.     p_term("t_vb", T_VB)
  2353.     p_term("t_ve", T_VE)
  2354.     p_term("t_vi", T_VI)
  2355.     p_term("t_vs", T_VS)
  2356.     p_term("t_WP", T_CWP)
  2357.     p_term("t_WS", T_CWS)
  2358.     p_term("t_xs", T_XS)
  2359.     p_term("t_ZH", T_CZH)
  2360.     p_term("t_ZR", T_CZR)
  2361.  
  2362. /* terminal key codes are not in here */
  2363.  
  2364.     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}}    /* end marker */
  2365. };
  2366.  
  2367. #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
  2368.  
  2369. #ifdef FEAT_MBYTE
  2370. static char *(p_ambw_values[]) = {"single", "double", NULL};
  2371. #endif
  2372. static char *(p_bg_values[]) = {"light", "dark", NULL};
  2373. static char *(p_bkc_values[]) = {"yes", "auto", "no", NULL};
  2374. static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
  2375. static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
  2376. #ifdef FEAT_WAK
  2377. static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
  2378. #endif
  2379. static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
  2380. #ifdef FEAT_VISUAL
  2381. static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
  2382. static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
  2383. #endif
  2384. #ifdef FEAT_VISUAL
  2385. static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
  2386. #endif
  2387. #ifdef FEAT_BROWSE
  2388. static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
  2389. #endif
  2390. #ifdef FEAT_SCROLLBIND
  2391. static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
  2392. #endif
  2393. static char *(p_swb_values[]) = {"useopen", "split", NULL};
  2394. static char *(p_debug_values[]) = {"msg", NULL};
  2395. #ifdef FEAT_VERTSPLIT
  2396. static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
  2397. #endif
  2398. #if defined(FEAT_QUICKFIX)
  2399. static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
  2400. static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
  2401. #endif
  2402. static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
  2403. #ifdef FEAT_FOLDING
  2404. static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
  2405. #ifdef FEAT_DIFF
  2406.                 "diff",
  2407. #endif
  2408.                 NULL};
  2409. static char *(p_fcl_values[]) = {"all", NULL};
  2410. #endif
  2411.  
  2412. static void set_option_default __ARGS((int, int opt_flags, int compatible));
  2413. static void set_options_default __ARGS((int opt_flags));
  2414. static char_u *illegal_char __ARGS((char_u *, int));
  2415. static int string_to_key __ARGS((char_u *arg));
  2416. #ifdef FEAT_CMDWIN
  2417. static char_u *check_cedit __ARGS((void));
  2418. #endif
  2419. #ifdef FEAT_TITLE
  2420. static void did_set_title __ARGS((int icon));
  2421. #endif
  2422. static char_u *option_expand __ARGS((int opt_idx, char_u *val));
  2423. static void didset_options __ARGS((void));
  2424. static void check_string_option __ARGS((char_u **pp));
  2425. static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
  2426. static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
  2427. static 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));
  2428. static char_u *set_chars_option __ARGS((char_u **varp));
  2429. #ifdef FEAT_CLIPBOARD
  2430. static char_u *check_clipboard_option __ARGS((void));
  2431. #endif
  2432. static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
  2433. static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, int opt_flags));
  2434. static void check_redraw __ARGS((long_u flags));
  2435. static int findoption __ARGS((char_u *));
  2436. static int find_key_option __ARGS((char_u *));
  2437. static void showoptions __ARGS((int all, int opt_flags));
  2438. static int optval_default __ARGS((struct vimoption *, char_u *varp));
  2439. static void showoneopt __ARGS((struct vimoption *, int opt_flags));
  2440. static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
  2441. static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
  2442. static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
  2443. static int  istermoption __ARGS((struct vimoption *));
  2444. static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
  2445. static char_u *get_varp __ARGS((struct vimoption *));
  2446. static void option_value2string __ARGS((struct vimoption *, int opt_flags));
  2447. static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
  2448. #ifdef FEAT_LANGMAP
  2449. static void langmap_init __ARGS((void));
  2450. static void langmap_set __ARGS((void));
  2451. #endif
  2452. static void paste_option_changed __ARGS((void));
  2453. static void compatible_set __ARGS((void));
  2454. #ifdef FEAT_LINEBREAK
  2455. static void fill_breakat_flags __ARGS((void));
  2456. #endif
  2457. static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
  2458. static int check_opt_strings __ARGS((char_u *val, char **values, int));
  2459. static int check_opt_wim __ARGS((void));
  2460.  
  2461. /*
  2462.  * Initialize the options, first part.
  2463.  *
  2464.  * Called only once from main(), just after creating the first buffer.
  2465.  */
  2466.     void
  2467. set_init_1()
  2468. {
  2469.     char_u    *p;
  2470.     int        opt_idx;
  2471.     long    n;
  2472.  
  2473. #ifdef FEAT_LANGMAP
  2474.     langmap_init();
  2475. #endif
  2476.  
  2477.     /* Be Vi compatible by default */
  2478.     p_cp = TRUE;
  2479.  
  2480.     /*
  2481.      * Find default value for 'shell' option.
  2482.      */
  2483.     if ((p = mch_getenv((char_u *)"SHELL")) != NULL
  2484. #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  2485. # ifdef __EMX__
  2486.         || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL
  2487. # endif
  2488.         || (p = mch_getenv((char_u *)"COMSPEC")) != NULL
  2489. # ifdef WIN3264
  2490.         || (p = default_shell()) != NULL
  2491. # endif
  2492. #endif
  2493.        )
  2494.     set_string_default("sh", p);
  2495.  
  2496. #ifdef FEAT_WILDIGN
  2497.     /*
  2498.      * Set the default for 'backupskip' to include environment variables for
  2499.      * temp files.
  2500.      */
  2501.     {
  2502. # ifdef UNIX
  2503.     static char    *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
  2504. # else
  2505.     static char    *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
  2506. # endif
  2507.     int    len;
  2508.     garray_T ga;
  2509.  
  2510.     ga_init2(&ga, 1, 100);
  2511.     for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
  2512.     {
  2513. # ifdef UNIX
  2514.         if (*names[n] == NUL)
  2515.         p = (char_u *)"/tmp";
  2516.         else
  2517. # endif
  2518.         p = mch_getenv((char_u *)names[n]);
  2519.         if (p != NULL && *p != NUL)
  2520.         {
  2521.         /* First time count the NUL, otherwise count the ','. */
  2522.         len = STRLEN(p) + 3;
  2523.         if (ga_grow(&ga, len) == OK)
  2524.         {
  2525.             if (ga.ga_len > 0)
  2526.             STRCAT(ga.ga_data, ",");
  2527.             STRCAT(ga.ga_data, p);
  2528.             add_pathsep(ga.ga_data);
  2529.             STRCAT(ga.ga_data, "*");
  2530.             ga.ga_room -= len;
  2531.             ga.ga_len += len;
  2532.         }
  2533.         }
  2534.     }
  2535.     if (ga.ga_data != NULL)
  2536.     {
  2537.         set_string_default("bsk", ga.ga_data);
  2538.         vim_free(ga.ga_data);
  2539.     }
  2540.     }
  2541. #endif
  2542.  
  2543.     /*
  2544.      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
  2545.      */
  2546.     opt_idx = findoption((char_u *)"maxmemtot");
  2547. #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
  2548.     if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
  2549. #endif
  2550.     {
  2551. #ifdef HAVE_AVAIL_MEM
  2552.     /* Use amount of memory available at this moment. */
  2553.     n = (mch_avail_mem(FALSE) >> 11);
  2554. #else
  2555. # ifdef HAVE_TOTAL_MEM
  2556.     /* Use amount of memory available to Vim. */
  2557.     n = (mch_total_mem(FALSE) >> 11);
  2558. # else
  2559.     n = (0x7fffffff >> 11);
  2560. # endif
  2561. #endif
  2562.     options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
  2563.     opt_idx = findoption((char_u *)"maxmem");
  2564. #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
  2565.     if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
  2566.               || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
  2567. #endif
  2568.         options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
  2569.     }
  2570.  
  2571. #ifdef FEAT_GUI_W32
  2572.     /* force 'shortname' for Win32s */
  2573.     if (gui_is_win32s())
  2574.     options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
  2575.                                    (char_u *)TRUE;
  2576. #endif
  2577.  
  2578. #ifdef FEAT_SEARCHPATH
  2579.     {
  2580.     char_u    *cdpath;
  2581.     char_u    *buf;
  2582.     int    i;
  2583.     int    j;
  2584.  
  2585.     /* Initialize the 'cdpath' option's default value. */
  2586.     cdpath = mch_getenv((char_u *)"CDPATH");
  2587.     if (cdpath != NULL)
  2588.     {
  2589.         buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
  2590.         if (buf != NULL)
  2591.         {
  2592.         buf[0] = ',';        /* start with ",", current dir first */
  2593.         j = 1;
  2594.         for (i = 0; cdpath[i] != NUL; ++i)
  2595.         {
  2596.             if (vim_ispathlistsep(cdpath[i]))
  2597.             buf[j++] = ',';
  2598.             else
  2599.             {
  2600.             if (cdpath[i] == ' ' || cdpath[i] == ',')
  2601.                 buf[j++] = '\\';
  2602.             buf[j++] = cdpath[i];
  2603.             }
  2604.         }
  2605.         buf[j] = NUL;
  2606.         opt_idx = findoption((char_u *)"cdpath");
  2607.         options[opt_idx].def_val[VI_DEFAULT] = buf;
  2608.         options[opt_idx].flags |= P_DEF_ALLOCED;
  2609.         }
  2610.     }
  2611.     }
  2612. #endif
  2613.  
  2614. #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
  2615.     /* Set print encoding on platforms that don't default to latin1 */
  2616.     set_string_default("penc",
  2617. # if defined(MSWIN) || defined(OS2)
  2618.                (char_u *)"cp1252"
  2619. # else
  2620. #  ifdef VMS
  2621.                (char_u *)"dec-mcs"
  2622. #  else
  2623. #   ifdef EBCDIC
  2624.                (char_u *)"ebcdic-uk"
  2625. #   else
  2626. #    ifdef MAC
  2627.                (char_u *)"mac-roman"
  2628. #    else /* HPUX */
  2629.                (char_u *)"hp-roman8"
  2630. #    endif
  2631. #   endif
  2632. #  endif
  2633. # endif
  2634.                );
  2635. #endif
  2636.  
  2637. #ifdef FEAT_POSTSCRIPT
  2638.     /* 'printexpr' must be allocated to be able to evaluate it. */
  2639.     set_string_default("pexpr",
  2640. # ifdef MSWIN
  2641.         (char_u *)"system('copy' . ' ' . v:fname_in . ' \"' . &printdevice . '\"') . delete(v:fname_in)"
  2642. # else
  2643. #  ifdef VMS
  2644.         (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
  2645.  
  2646. #  else
  2647.         (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
  2648. #  endif
  2649. # endif
  2650.         );
  2651. #endif
  2652.  
  2653.     /*
  2654.      * Set all the options (except the terminal options) to their default
  2655.      * value.  Also set the global value for local options.
  2656.      */
  2657.     set_options_default(0);
  2658.  
  2659. #ifdef FEAT_GUI
  2660.     if (found_reverse_arg)
  2661.     set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
  2662. #endif
  2663.  
  2664.     curbuf->b_p_initialized = TRUE;
  2665.     curbuf->b_p_ar = -1;    /* no local 'autoread' value */
  2666.     check_buf_options(curbuf);
  2667.     check_win_options(curwin);
  2668.     check_options();
  2669.  
  2670.     /* Must be before option_expand(), because that one needs vim_isIDc() */
  2671.     didset_options();
  2672.  
  2673. #ifdef FEAT_LINEBREAK
  2674.     /*
  2675.      * initialize the table for 'breakat'.
  2676.      */
  2677.     fill_breakat_flags();
  2678. #endif
  2679.  
  2680.     /*
  2681.      * Expand environment variables and things like "~" for the defaults.
  2682.      * If option_expand() returns non-NULL the variable is expanded.  This can
  2683.      * only happen for non-indirect options.
  2684.      * Also set the default to the expanded value, so ":set" does not list
  2685.      * them.
  2686.      * Don't set the P_ALLOCED flag, because we don't want to free the
  2687.      * default.
  2688.      */
  2689.     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
  2690.     {
  2691.     if ((options[opt_idx].flags & P_GETTEXT)
  2692.                           && options[opt_idx].var != NULL)
  2693.         p = (char_u *)_(*(char **)options[opt_idx].var);
  2694.     else
  2695.         p = option_expand(opt_idx, NULL);
  2696.     if (p != NULL && (p = vim_strsave(p)) != NULL)
  2697.     {
  2698.         *(char_u **)options[opt_idx].var = p;
  2699.         /* VIMEXP
  2700.          * Defaults for all expanded options are currently the same for Vi
  2701.          * and Vim.  When this changes, add some code here!  Also need to
  2702.          * split P_DEF_ALLOCED in two.
  2703.          */
  2704.         if (options[opt_idx].flags & P_DEF_ALLOCED)
  2705.         vim_free(options[opt_idx].def_val[VI_DEFAULT]);
  2706.         options[opt_idx].def_val[VI_DEFAULT] = p;
  2707.         options[opt_idx].flags |= P_DEF_ALLOCED;
  2708.     }
  2709.     }
  2710.  
  2711.     /* Initialize the highlight_attr[] table. */
  2712.     highlight_changed();
  2713.  
  2714.     save_file_ff(curbuf);    /* Buffer is unchanged */
  2715.  
  2716.     /* Parse default for 'wildmode'  */
  2717.     check_opt_wim();
  2718.  
  2719. #if defined(FEAT_ARABIC)
  2720.     /* Detect use of mlterm.
  2721.      * Mlterm is a terminal emulator akin to xterm that has some special
  2722.      * abilities (bidi namely).
  2723.      * NOTE: mlterm's author is being asked to 'set' a variable
  2724.      *       instead of an environment variable due to inheritance.
  2725.      */
  2726.     if (mch_getenv((char_u *)"MLTERM") != NULL)
  2727.     set_option_value((char_u *)"tbidi", 1L, NULL, 0);
  2728. #endif
  2729.  
  2730. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  2731.     /* Parse default for 'fillchars'. */
  2732.     (void)set_chars_option(&p_fcs);
  2733. #endif
  2734.  
  2735. #ifdef FEAT_CLIPBOARD
  2736.     /* Parse default for 'clipboard' */
  2737.     (void)check_clipboard_option();
  2738. #endif
  2739.  
  2740. #ifdef FEAT_MBYTE
  2741. # if defined(WIN3264) && defined(FEAT_GETTEXT)
  2742.     /*
  2743.      * If $LANG isn't set, try to get a good value for it.  This makes the
  2744.      * right language be used automatically.  Don't do this for English.
  2745.      */
  2746.     if (mch_getenv((char_u *)"LANG") == NULL)
  2747.     {
  2748.     char    buf[20];
  2749.  
  2750.     /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
  2751.      * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
  2752.      * only the first two. */
  2753.     n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
  2754.                                  (LPTSTR)buf, 20);
  2755.     if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
  2756.     {
  2757.         /* There are a few exceptions (probably more) */
  2758.         if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
  2759.         STRCPY(buf, "zh_TW");
  2760.         else if (STRNICMP(buf, "chs", 3) == 0
  2761.                           || STRNICMP(buf, "zhc", 3) == 0)
  2762.         STRCPY(buf, "zh_CN");
  2763.         else if (STRNICMP(buf, "jp", 2) == 0)
  2764.         STRCPY(buf, "ja");
  2765.         else
  2766.         buf[2] = NUL;        /* truncate to two-letter code */
  2767.         vim_setenv("LANG", buf);
  2768.     }
  2769.     }
  2770. # endif
  2771.  
  2772.     /* enc_locale() will try to find the encoding of the current locale. */
  2773.     p = enc_locale();
  2774.     if (p != NULL)
  2775.     {
  2776.     char_u *save_enc;
  2777.  
  2778.     /* Try setting 'encoding' and check if the value is valid.
  2779.      * If not, go back to the default "latin1". */
  2780.     save_enc = p_enc;
  2781.     p_enc = p;
  2782.     if (mb_init() == NULL)
  2783.     {
  2784.         opt_idx = findoption((char_u *)"encoding");
  2785.         options[opt_idx].def_val[VI_DEFAULT] = p_enc;
  2786.         options[opt_idx].flags |= P_DEF_ALLOCED;
  2787.     }
  2788.     else
  2789.     {
  2790.         vim_free(p_enc);
  2791.         p_enc = save_enc;
  2792.     }
  2793.     }
  2794. #endif
  2795. }
  2796.  
  2797. /*
  2798.  * Set an option to its default value.
  2799.  * This does not take care of side effects!
  2800.  */
  2801.     static void
  2802. set_option_default(opt_idx, opt_flags, compatible)
  2803.     int        opt_idx;
  2804.     int        opt_flags;    /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
  2805.     int        compatible;    /* use Vi default value */
  2806. {
  2807.     char_u    *varp;        /* pointer to variable for current option */
  2808.     int        dvi;        /* index in def_val[] */
  2809.     long_u    flags;
  2810.     int        both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
  2811.  
  2812.     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
  2813.     flags = options[opt_idx].flags;
  2814.     if (varp != NULL)        /* nothing to do for hidden option */
  2815.     {
  2816.     dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
  2817.     if (flags & P_STRING)
  2818.     {
  2819.         /* Use set_string_option_direct() for local options to handle
  2820.          * freeing and allocating the value. */
  2821.         if (options[opt_idx].indir != PV_NONE)
  2822.         set_string_option_direct(NULL, opt_idx,
  2823.                     options[opt_idx].def_val[dvi], opt_flags);
  2824.         else
  2825.         {
  2826.         if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
  2827.             free_string_option(*(char_u **)(varp));
  2828.         *(char_u **)varp = options[opt_idx].def_val[dvi];
  2829.         options[opt_idx].flags &= ~P_ALLOCED;
  2830.         }
  2831.     }
  2832.     else if (flags & P_NUM)
  2833.     {
  2834.         if (varp == (char_u *)PV_SCROLL)
  2835.         win_comp_scroll(curwin);
  2836.         else
  2837.         {
  2838.         *(long *)varp = (long)options[opt_idx].def_val[dvi];
  2839.         /* May also set global value for local option. */
  2840.         if (both)
  2841.             *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
  2842.                                 *(long *)varp;
  2843.         }
  2844.     }
  2845.     else    /* P_BOOL */
  2846.     {
  2847.         /* the cast to long is required for Manx C */
  2848.         *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
  2849.         /* May also set global value for local option. */
  2850.         if (both)
  2851.         *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
  2852.                                 *(int *)varp;
  2853.     }
  2854.     }
  2855.  
  2856. #ifdef FEAT_EVAL
  2857.     /* Remember where the option was set. */
  2858.     options[opt_idx].scriptID = current_SID;
  2859. #endif
  2860. }
  2861.  
  2862. /*
  2863.  * Set all options (except terminal options) to their default value.
  2864.  */
  2865.     static void
  2866. set_options_default(opt_flags)
  2867.     int        opt_flags;    /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
  2868. {
  2869.     int        i;
  2870. #ifdef FEAT_WINDOWS
  2871.     win_T    *wp;
  2872. #endif
  2873.  
  2874.     for (i = 0; !istermoption(&options[i]); i++)
  2875.     if (!(options[i].flags & P_NODEFAULT))
  2876.         set_option_default(i, opt_flags, p_cp);
  2877.  
  2878. #ifdef FEAT_WINDOWS
  2879.     /* The 'scroll' option must be computed for all windows. */
  2880.     for (wp = firstwin; wp != NULL; wp = wp->w_next)
  2881.     win_comp_scroll(wp);
  2882. #else
  2883.     win_comp_scroll(curwin);
  2884. #endif
  2885. }
  2886.  
  2887. /*
  2888.  * Set the Vi-default value of a string option.
  2889.  * Used for 'sh', 'backupskip' and 'term'.
  2890.  */
  2891.     void
  2892. set_string_default(name, val)
  2893.     char    *name;
  2894.     char_u    *val;
  2895. {
  2896.     char_u    *p;
  2897.     int        opt_idx;
  2898.  
  2899.     p = vim_strsave(val);
  2900.     if (p != NULL)        /* we don't want a NULL */
  2901.     {
  2902.     opt_idx = findoption((char_u *)name);
  2903.     if (options[opt_idx].flags & P_DEF_ALLOCED)
  2904.         vim_free(options[opt_idx].def_val[VI_DEFAULT]);
  2905.     options[opt_idx].def_val[VI_DEFAULT] = p;
  2906.     options[opt_idx].flags |= P_DEF_ALLOCED;
  2907.     }
  2908. }
  2909.  
  2910. /*
  2911.  * Set the Vi-default value of a number option.
  2912.  * Used for 'lines' and 'columns'.
  2913.  */
  2914.     void
  2915. set_number_default(name, val)
  2916.     char    *name;
  2917.     long    val;
  2918. {
  2919.     options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
  2920. }
  2921.  
  2922. /*
  2923.  * Initialize the options, part two: After getting Rows and Columns and
  2924.  * setting 'term'.
  2925.  */
  2926.     void
  2927. set_init_2()
  2928. {
  2929.     /*
  2930.      * 'scroll' defaults to half the window height. Note that this default is
  2931.      * wrong when the window height changes.
  2932.      */
  2933.     options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT]
  2934.                           = (char_u *)((long_u)Rows >> 1);
  2935.     comp_col();
  2936.  
  2937. #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
  2938.     {
  2939.     int    idx4;
  2940.  
  2941.     /*
  2942.      * If 'background' wasn't set by the user, try guessing the value,
  2943.      * depending on the terminal name.  Only need to check for terminals
  2944.      * with a dark background, that can handle color.  Only "linux"
  2945.      * console at the moment.
  2946.      */
  2947.     idx4 = findoption((char_u *)"bg");
  2948.     if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0)
  2949.     {
  2950.         set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE);
  2951.         /* don't mark it as set, when starting the GUI it may be changed
  2952.          * again */
  2953.         options[idx4].flags &= ~P_WAS_SET;
  2954.     }
  2955.     }
  2956. #endif
  2957. }
  2958.  
  2959. /*
  2960.  * Initialize the options, part three: After reading the .vimrc
  2961.  */
  2962.     void
  2963. set_init_3()
  2964. {
  2965. #if defined(UNIX) || defined(OS2) || defined(WIN3264)
  2966. /*
  2967.  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
  2968.  * This is done after other initializations, where 'shell' might have been
  2969.  * set, but only if they have not been set before.
  2970.  */
  2971.     char_u  *p;
  2972.     int        idx_srr;
  2973.     int        do_srr;
  2974. #ifdef FEAT_QUICKFIX
  2975.     int        idx_sp;
  2976.     int        do_sp;
  2977. #endif
  2978.  
  2979.     idx_srr = findoption((char_u *)"srr");
  2980.     do_srr = !(options[idx_srr].flags & P_WAS_SET);
  2981. #ifdef FEAT_QUICKFIX
  2982.     idx_sp = findoption((char_u *)"sp");
  2983.     do_sp = !(options[idx_sp].flags & P_WAS_SET);
  2984. #endif
  2985.  
  2986.     /*
  2987.      * Isolate the name of the shell:
  2988.      * - Skip beyond any path.  E.g., "/usr/bin/csh -f" -> "csh -f".
  2989.      * - Remove any argument.  E.g., "csh -f" -> "csh".
  2990.      */
  2991.     p = gettail(p_sh);
  2992.     p = vim_strnsave(p, (int)(skiptowhite(p) - p));
  2993.     if (p != NULL)
  2994.     {
  2995.     /*
  2996.      * Default for p_sp is "| tee", for p_srr is ">".
  2997.      * For known shells it is changed here to include stderr.
  2998.      */
  2999.     if (       fnamecmp(p, "csh") == 0
  3000.         || fnamecmp(p, "tcsh") == 0
  3001. # if defined(OS2) || defined(WIN3264)    /* also check with .exe extension */
  3002.         || fnamecmp(p, "csh.exe") == 0
  3003.         || fnamecmp(p, "tcsh.exe") == 0
  3004. # endif
  3005.        )
  3006.     {
  3007. #if defined(FEAT_QUICKFIX)
  3008.         if (do_sp)
  3009.         {
  3010. # ifdef WIN3264
  3011.         p_sp = (char_u *)">&";
  3012. # else
  3013.         p_sp = (char_u *)"|& tee";
  3014. # endif
  3015.         options[idx_sp].def_val[VI_DEFAULT] = p_sp;
  3016.         }
  3017. #endif
  3018.         if (do_srr)
  3019.         {
  3020.         p_srr = (char_u *)">&";
  3021.         options[idx_srr].def_val[VI_DEFAULT] = p_srr;
  3022.         }
  3023.     }
  3024.     else
  3025. # ifndef OS2    /* Always use bourne shell style redirection if we reach this */
  3026.         if (       fnamecmp(p, "sh") == 0
  3027.             || fnamecmp(p, "ksh") == 0
  3028.             || fnamecmp(p, "zsh") == 0
  3029.             || fnamecmp(p, "bash") == 0
  3030. #  ifdef WIN3264
  3031.             || fnamecmp(p, "cmd") == 0
  3032.             || fnamecmp(p, "sh.exe") == 0
  3033.             || fnamecmp(p, "ksh.exe") == 0
  3034.             || fnamecmp(p, "zsh.exe") == 0
  3035.             || fnamecmp(p, "bash.exe") == 0
  3036.             || fnamecmp(p, "cmd.exe") == 0
  3037. #  endif
  3038.             )
  3039. # endif
  3040.         {
  3041. #if defined(FEAT_QUICKFIX)
  3042.         if (do_sp)
  3043.         {
  3044. # ifdef WIN3264
  3045.             p_sp = (char_u *)">%s 2>&1";
  3046. # else
  3047.             p_sp = (char_u *)"2>&1| tee";
  3048. # endif
  3049.             options[idx_sp].def_val[VI_DEFAULT] = p_sp;
  3050.         }
  3051. #endif
  3052.         if (do_srr)
  3053.         {
  3054.             p_srr = (char_u *)">%s 2>&1";
  3055.             options[idx_srr].def_val[VI_DEFAULT] = p_srr;
  3056.         }
  3057.         }
  3058.     vim_free(p);
  3059.     }
  3060. #endif
  3061.  
  3062. #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
  3063.     /*
  3064.      * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
  3065.      * This is done after other initializations, where 'shell' might have been
  3066.      * set, but only if they have not been set before.  Default for p_shcf is
  3067.      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
  3068.      * "-c" and "\"", but not for DJGPP, because it starts the shell without
  3069.      * command.com.  And for Win32 we need to set p_sxq instead.
  3070.      */
  3071.     if (strstr((char *)p_sh, "sh") != NULL)
  3072.     {
  3073.     int    idx3;
  3074.  
  3075.     idx3 = findoption((char_u *)"shcf");
  3076.     if (!(options[idx3].flags & P_WAS_SET))
  3077.     {
  3078.         p_shcf = (char_u *)"-c";
  3079.         options[idx3].def_val[VI_DEFAULT] = p_shcf;
  3080.     }
  3081.  
  3082. # ifndef DJGPP
  3083. #  ifdef WIN3264
  3084.     /* Somehow Win32 requires the quotes around the redirection too */
  3085.     idx3 = findoption((char_u *)"sxq");
  3086.     if (!(options[idx3].flags & P_WAS_SET))
  3087.     {
  3088.         p_sxq = (char_u *)"\"";
  3089.         options[idx3].def_val[VI_DEFAULT] = p_sxq;
  3090.     }
  3091. #  else
  3092.     idx3 = findoption((char_u *)"shq");
  3093.     if (!(options[idx3].flags & P_WAS_SET))
  3094.     {
  3095.         p_shq = (char_u *)"\"";
  3096.         options[idx3].def_val[VI_DEFAULT] = p_shq;
  3097.     }
  3098. #  endif
  3099. # endif
  3100.     }
  3101. #endif
  3102.  
  3103. #ifdef FEAT_TITLE
  3104.     set_title_defaults();
  3105. #endif
  3106. }
  3107.  
  3108. #ifdef FEAT_GUI
  3109. static char_u *gui_bg_default __ARGS((void));
  3110.  
  3111.     static char_u *
  3112. gui_bg_default()
  3113. {
  3114.     if (gui_get_lightness(gui.back_pixel) < 127)
  3115.     return (char_u *)"dark";
  3116.     return (char_u *)"light";
  3117. }
  3118.  
  3119. /*
  3120.  * Option initializations that can only be done after opening the GUI window.
  3121.  */
  3122.     void
  3123. init_gui_options()
  3124. {
  3125.     /* Set the 'background' option according to the lightness of the
  3126.      * background color, unless the user has set it already. */
  3127.     if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
  3128.     {
  3129.     set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
  3130.     highlight_changed();
  3131.     }
  3132. }
  3133. #endif
  3134.  
  3135. #ifdef FEAT_TITLE
  3136. /*
  3137.  * 'title' and 'icon' only default to true if they have not been set or reset
  3138.  * in .vimrc and we can read the old value.
  3139.  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
  3140.  * they can be reset.  This reduces startup time when using X on a remote
  3141.  * machine.
  3142.  */
  3143.     void
  3144. set_title_defaults()
  3145. {
  3146.     int        idx1;
  3147.     long    val;
  3148.  
  3149.     /*
  3150.      * If GUI is (going to be) used, we can always set the window title and
  3151.      * icon name.  Saves a bit of time, because the X11 display server does
  3152.      * not need to be contacted.
  3153.      */
  3154.     idx1 = findoption((char_u *)"title");
  3155.     if (!(options[idx1].flags & P_WAS_SET))
  3156.     {
  3157. #ifdef FEAT_GUI
  3158.     if (gui.starting || gui.in_use)
  3159.         val = TRUE;
  3160.     else
  3161. #endif
  3162.         val = mch_can_restore_title();
  3163.     options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
  3164.     p_title = val;
  3165.     }
  3166.     idx1 = findoption((char_u *)"icon");
  3167.     if (!(options[idx1].flags & P_WAS_SET))
  3168.     {
  3169. #ifdef FEAT_GUI
  3170.     if (gui.starting || gui.in_use)
  3171.         val = TRUE;
  3172.     else
  3173. #endif
  3174.         val = mch_can_restore_icon();
  3175.     options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
  3176.     p_icon = val;
  3177.     }
  3178. }
  3179. #endif
  3180.  
  3181. /*
  3182.  * Parse 'arg' for option settings.
  3183.  *
  3184.  * 'arg' may be IObuff, but only when no errors can be present and option
  3185.  * does not need to be expanded with option_expand().
  3186.  * "opt_flags":
  3187.  * 0 for ":set"
  3188.  * OPT_GLOBAL for ":setglobal"
  3189.  * OPT_LOCAL for ":setlocal" and a modeline
  3190.  * OPT_MODELINE for a modeline
  3191.  *
  3192.  * returns FAIL if an error is detected, OK otherwise
  3193.  */
  3194.     int
  3195. do_set(arg, opt_flags)
  3196.     char_u    *arg;        /* option string (may be written to!) */
  3197.     int        opt_flags;
  3198. {
  3199.     int        opt_idx;
  3200.     char_u    *errmsg;
  3201.     char_u    errbuf[80];
  3202.     char_u    *startarg;
  3203.     int        prefix;    /* 1: nothing, 0: "no", 2: "inv" in front of name */
  3204.     int        nextchar;        /* next non-white char after option name */
  3205.     int        afterchar;        /* character just after option name */
  3206.     int        len;
  3207.     int        i;
  3208.     long    value;
  3209.     int        key;
  3210.     long_u    flags;            /* flags for current option */
  3211.     char_u    *varp = NULL;        /* pointer to variable for current option */
  3212.     int        did_show = FALSE;   /* already showed one value */
  3213.     int        adding;            /* "opt+=arg" */
  3214.     int        prepending;        /* "opt^=arg" */
  3215.     int        removing;        /* "opt-=arg" */
  3216.     int        cp_val = 0;
  3217.     char_u    key_name[2];
  3218.  
  3219.     if (*arg == NUL)
  3220.     {
  3221.     showoptions(0, opt_flags);
  3222.     return OK;
  3223.     }
  3224.  
  3225.     while (*arg != NUL)        /* loop to process all options */
  3226.     {
  3227.     errmsg = NULL;
  3228.     startarg = arg;        /* remember for error message */
  3229.  
  3230.     if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]))
  3231.     {
  3232.         /*
  3233.          * ":set all"  show all options.
  3234.          * ":set all&" set all options to their default value.
  3235.          */
  3236.         arg += 3;
  3237.         if (*arg == '&')
  3238.         {
  3239.         ++arg;
  3240.         /* Only for :set command set global value of local options. */
  3241.         set_options_default(OPT_FREE | opt_flags);
  3242.         }
  3243.         else
  3244.         showoptions(1, opt_flags);
  3245.     }
  3246.     else if (STRNCMP(arg, "termcap", 7) == 0)
  3247.     {
  3248.         showoptions(2, opt_flags);
  3249.         show_termcodes();
  3250.         arg += 7;
  3251.     }
  3252.     else
  3253.     {
  3254.         prefix = 1;
  3255.         if (STRNCMP(arg, "no", 2) == 0)
  3256.         {
  3257.         prefix = 0;
  3258.         arg += 2;
  3259.         }
  3260.         else if (STRNCMP(arg, "inv", 3) == 0)
  3261.         {
  3262.         prefix = 2;
  3263.         arg += 3;
  3264.         }
  3265.  
  3266.         /* find end of name */
  3267.         key = 0;
  3268.         if (*arg == '<')
  3269.         {
  3270.         nextchar = 0;
  3271.         opt_idx = -1;
  3272.         /* look out for <t_>;> */
  3273.         if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
  3274.             len = 5;
  3275.         else
  3276.         {
  3277.             len = 1;
  3278.             while (arg[len] != NUL && arg[len] != '>')
  3279.             ++len;
  3280.         }
  3281.         if (arg[len] != '>')
  3282.         {
  3283.             errmsg = e_invarg;
  3284.             goto skip;
  3285.         }
  3286.         arg[len] = NUL;                /* put NUL after name */
  3287.         if (arg[1] == 't' && arg[2] == '_') /* could be term code */
  3288.             opt_idx = findoption(arg + 1);
  3289.         arg[len++] = '>';            /* restore '>' */
  3290.         if (opt_idx == -1)
  3291.             key = find_key_option(arg + 1);
  3292.         }
  3293.         else
  3294.         {
  3295.         len = 0;
  3296.         /*
  3297.          * The two characters after "t_" may not be alphanumeric.
  3298.          */
  3299.         if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
  3300.             len = 4;
  3301.         else
  3302.             while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
  3303.             ++len;
  3304.         nextchar = arg[len];
  3305.         arg[len] = NUL;                /* put NUL after name */
  3306.         opt_idx = findoption(arg);
  3307.         arg[len] = nextchar;            /* restore nextchar */
  3308.         if (opt_idx == -1)
  3309.             key = find_key_option(arg);
  3310.         }
  3311.  
  3312.         /* remember character after option name */
  3313.         afterchar = arg[len];
  3314.  
  3315.         /* skip white space, allow ":set ai  ?" */
  3316.         while (vim_iswhite(arg[len]))
  3317.         ++len;
  3318.  
  3319.         adding = FALSE;
  3320.         prepending = FALSE;
  3321.         removing = FALSE;
  3322.         if (arg[len] != NUL && arg[len + 1] == '=')
  3323.         {
  3324.         if (arg[len] == '+')
  3325.         {
  3326.             adding = TRUE;        /* "+=" */
  3327.             ++len;
  3328.         }
  3329.         else if (arg[len] == '^')
  3330.         {
  3331.             prepending = TRUE;        /* "^=" */
  3332.             ++len;
  3333.         }
  3334.         else if (arg[len] == '-')
  3335.         {
  3336.             removing = TRUE;        /* "-=" */
  3337.             ++len;
  3338.         }
  3339.         }
  3340.         nextchar = arg[len];
  3341.  
  3342.         if (opt_idx == -1 && key == 0)    /* found a mismatch: skip */
  3343.         {
  3344.         errmsg = (char_u *)N_("E518: Unknown option");
  3345.         goto skip;
  3346.         }
  3347.  
  3348.         if (opt_idx >= 0)
  3349.         {
  3350.         if (options[opt_idx].var == NULL)   /* hidden option: skip */
  3351.         {
  3352.             /* Only give an error message when requesting the value of
  3353.              * a hidden option, ignore setting it. */
  3354.             if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
  3355.                 && (!(options[opt_idx].flags & P_BOOL)
  3356.                 || nextchar == '?'))
  3357.             errmsg = (char_u *)N_("E519: Option not supported");
  3358.             goto skip;
  3359.         }
  3360.  
  3361.         flags = options[opt_idx].flags;
  3362.         varp = get_varp_scope(&(options[opt_idx]), opt_flags);
  3363.         }
  3364.         else
  3365.         {
  3366.         flags = P_STRING;
  3367.         if (key < 0)
  3368.         {
  3369.             key_name[0] = KEY2TERMCAP0(key);
  3370.             key_name[1] = KEY2TERMCAP1(key);
  3371.         }
  3372.         else
  3373.         {
  3374.             key_name[0] = KS_KEY;
  3375.             key_name[1] = (key & 0xff);
  3376.         }
  3377.         }
  3378.  
  3379.         /* Disallow changing some options from modelines */
  3380.         if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
  3381.         {
  3382.         errmsg = (char_u *)_("E520: Not allowed in a modeline");
  3383.         goto skip;
  3384.         }
  3385.  
  3386.         if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
  3387.         {
  3388.         arg += len;
  3389.         cp_val = p_cp;
  3390.         if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
  3391.         {
  3392.             if (arg[3] == 'm')    /* "opt&vim": set to Vim default */
  3393.             {
  3394.             cp_val = FALSE;
  3395.             arg += 3;
  3396.             }
  3397.             else        /* "opt&vi": set to Vi default */
  3398.             {
  3399.             cp_val = TRUE;
  3400.             arg += 2;
  3401.             }
  3402.         }
  3403.         if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
  3404.             && arg[1] != NUL && !vim_iswhite(arg[1]))
  3405.         {
  3406.             errmsg = e_trailing;
  3407.             goto skip;
  3408.         }
  3409.         }
  3410.  
  3411.         /*
  3412.          * allow '=' and ':' as MSDOS command.com allows only one
  3413.          * '=' character per "set" command line. grrr. (jw)
  3414.          */
  3415.         if (nextchar == '?'
  3416.             || (prefix == 1
  3417.             && vim_strchr((char_u *)"=:&<", nextchar) == NULL
  3418.             && !(flags & P_BOOL)))
  3419.         {
  3420.         /*
  3421.          * print value
  3422.          */
  3423.         if (did_show)
  3424.             msg_putchar('\n');        /* cursor below last one */
  3425.         else
  3426.         {
  3427.             gotocmdline(TRUE);        /* cursor at status line */
  3428.             did_show = TRUE;        /* remember that we did a line */
  3429.         }
  3430.         if (opt_idx >= 0)
  3431.         {
  3432.             showoneopt(&options[opt_idx], opt_flags);
  3433. #ifdef FEAT_EVAL
  3434.             if (p_verbose > 0)
  3435.             {
  3436.             if (options[opt_idx].scriptID != 0)
  3437.             {
  3438.                 MSG_PUTS(_("\n\tLast set from "));
  3439.                 MSG_PUTS(get_scriptname(options[opt_idx].scriptID));
  3440.             }
  3441.             }
  3442. #endif
  3443.         }
  3444.         else
  3445.         {
  3446.             char_u        *p;
  3447.  
  3448.             p = find_termcode(key_name);
  3449.             if (p == NULL)
  3450.             {
  3451.             errmsg = (char_u *)N_("E518: Unknown option");
  3452.             goto skip;
  3453.             }
  3454.             else
  3455.             (void)show_one_termcode(key_name, p, TRUE);
  3456.         }
  3457.         if (nextchar != '?'
  3458.             && nextchar != NUL && !vim_iswhite(afterchar))
  3459.             errmsg = e_trailing;
  3460.         }
  3461.         else
  3462.         {
  3463.         if (flags & P_BOOL)            /* boolean */
  3464.         {
  3465.             if (nextchar == '=' || nextchar == ':')
  3466.             {
  3467.             errmsg = e_invarg;
  3468.             goto skip;
  3469.             }
  3470.  
  3471.             /*
  3472.              * ":set opt!": invert
  3473.              * ":set opt&": reset to default value
  3474.              * ":set opt<": reset to global value
  3475.              */
  3476.             if (nextchar == '!')
  3477.             value = *(int *)(varp) ^ 1;
  3478.             else if (nextchar == '&')
  3479.             value = (int)(long)options[opt_idx].def_val[
  3480.                         ((flags & P_VI_DEF) || cp_val)
  3481.                          ?  VI_DEFAULT : VIM_DEFAULT];
  3482.             else if (nextchar == '<')
  3483.             {
  3484.             /* For 'autoread' -1 means to use global value. */
  3485.             if ((int *)varp == &curbuf->b_p_ar
  3486.                             && opt_flags == OPT_LOCAL)
  3487.                 value = -1;
  3488.             else
  3489.                 value = *(int *)get_varp_scope(&(options[opt_idx]),
  3490.                                   OPT_GLOBAL);
  3491.             }
  3492.             else
  3493.             {
  3494.             /*
  3495.              * ":set invopt": invert
  3496.              * ":set opt" or ":set noopt": set or reset
  3497.              */
  3498.             if (nextchar != NUL && !vim_iswhite(afterchar))
  3499.             {
  3500.                 errmsg = e_trailing;
  3501.                 goto skip;
  3502.             }
  3503.             if (prefix == 2)    /* inv */
  3504.                 value = *(int *)(varp) ^ 1;
  3505.             else
  3506.                 value = prefix;
  3507.             }
  3508.  
  3509.             errmsg = set_bool_option(opt_idx, varp, (int)value,
  3510.                                    opt_flags);
  3511.         }
  3512.         else                    /* numeric or string */
  3513.         {
  3514.             if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
  3515.                                    || prefix != 1)
  3516.             {
  3517.             errmsg = e_invarg;
  3518.             goto skip;
  3519.             }
  3520.  
  3521.             if (flags & P_NUM)            /* numeric */
  3522.             {
  3523.             /*
  3524.              * Different ways to set a number option:
  3525.              * &        set to default value
  3526.              * <        set to global value
  3527.              * <xx>        accept special key codes for 'wildchar'
  3528.              * c        accept any non-digit for 'wildchar'
  3529.              * [-]0-9   set number
  3530.              * other    error
  3531.              */
  3532.             ++arg;
  3533.             if (nextchar == '&')
  3534.                 value = (long)options[opt_idx].def_val[
  3535.                         ((flags & P_VI_DEF) || cp_val)
  3536.                          ?  VI_DEFAULT : VIM_DEFAULT];
  3537.             else if (nextchar == '<')
  3538.                 value = *(long *)get_varp_scope(&(options[opt_idx]),
  3539.                                   OPT_GLOBAL);
  3540.             else if (((long *)varp == &p_wc
  3541.                     || (long *)varp == &p_wcm)
  3542.                 && (*arg == '<'
  3543.                     || *arg == '^'
  3544.                     || ((!arg[1] || vim_iswhite(arg[1]))
  3545.                     && !isdigit(*arg))))
  3546.             {
  3547.                 value = string_to_key(arg);
  3548.                 if (value == 0 && (long *)varp != &p_wcm)
  3549.                 {
  3550.                 errmsg = e_invarg;
  3551.                 goto skip;
  3552.                 }
  3553.             }
  3554.                 /* allow negative numbers (for 'undolevels') */
  3555.             else if (*arg == '-' || isdigit(*arg))
  3556.             {
  3557.                 i = 0;
  3558.                 if (*arg == '-')
  3559.                 i = 1;
  3560. #ifdef HAVE_STRTOL
  3561.                 value = strtol((char *)arg, NULL, 0);
  3562.                 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
  3563.                 i += 2;
  3564. #else
  3565.                 value = atol((char *)arg);
  3566. #endif
  3567.                 while (isdigit(arg[i]))
  3568.                 ++i;
  3569.                 if (arg[i] != NUL && !vim_iswhite(arg[i]))
  3570.                 {
  3571.                 errmsg = e_invarg;
  3572.                 goto skip;
  3573.                 }
  3574.             }
  3575.             else
  3576.             {
  3577.                 errmsg = (char_u *)N_("E521: Number required after =");
  3578.                 goto skip;
  3579.             }
  3580.  
  3581.             if (adding)
  3582.                 value = *(long *)varp + value;
  3583.             if (prepending)
  3584.                 value = *(long *)varp * value;
  3585.             if (removing)
  3586.                 value = *(long *)varp - value;
  3587.             errmsg = set_num_option(opt_idx, varp, value,
  3588.                                errbuf, opt_flags);
  3589.             }
  3590.             else if (opt_idx >= 0)            /* string */
  3591.             {
  3592.             char_u        *save_arg = NULL;
  3593.             char_u        *s = NULL;
  3594.             char_u        *oldval;    /* previous value if *varp */
  3595.             char_u        *newval;
  3596.             char_u        *origval;
  3597.             unsigned    newlen;
  3598.             int        comma;
  3599.             int        bs;
  3600.             int        new_value_alloced;    /* new string option
  3601.                                was allocated */
  3602.  
  3603.             /* When using ":set opt=val" for a global option
  3604.              * with a local value the local value will be
  3605.              * reset, use the global value here. */
  3606.             if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
  3607.                 && (int)options[opt_idx].indir >= PV_BOTH)
  3608.                 varp = options[opt_idx].var;
  3609.  
  3610.             /* The old value is kept until we are sure that the
  3611.              * new value is valid. */
  3612.             oldval = *(char_u **)varp;
  3613.             if (nextchar == '&')    /* set to default val */
  3614.             {
  3615.                 newval = options[opt_idx].def_val[
  3616.                         ((flags & P_VI_DEF) || cp_val)
  3617.                          ?  VI_DEFAULT : VIM_DEFAULT];
  3618.                 if ((char_u **)varp == &p_bg)
  3619.                 {
  3620.                 /* guess the value of 'background' */
  3621. #ifdef FEAT_GUI
  3622.                 if (gui.in_use)
  3623.                     newval = gui_bg_default();
  3624.                 else
  3625. #endif
  3626.                     if (STRCMP(T_NAME, "linux") == 0)
  3627.                     newval = (char_u *)"dark";
  3628.                 }
  3629.  
  3630.                 /* expand environment variables and ~ (since the
  3631.                  * default value was already expanded, only
  3632.                  * required when an environment variable was set
  3633.                  * later */
  3634.                 if (newval == NULL)
  3635.                 newval = empty_option;
  3636.                 else
  3637.                 {
  3638.                 s = option_expand(opt_idx, newval);
  3639.                 if (s == NULL)
  3640.                     s = newval;
  3641.                 newval = vim_strsave(s);
  3642.                 }
  3643.                 new_value_alloced = TRUE;
  3644.             }
  3645.             else if (nextchar == '<')    /* set to global val */
  3646.             {
  3647.                 newval = vim_strsave(*(char_u **)get_varp_scope(
  3648.                          &(options[opt_idx]), OPT_GLOBAL));
  3649.                 new_value_alloced = TRUE;
  3650.             }
  3651.             else
  3652.             {
  3653.                 ++arg;    /* jump to after the '=' or ':' */
  3654.  
  3655.                 /*
  3656.                  * Set 'keywordprg' to ":help" if an empty
  3657.                  * value was passed to :set by the user.
  3658.                  * Misuse errbuf[] for the resulting string.
  3659.                  */
  3660.                 if (varp == (char_u *)&p_kp
  3661.                           && (*arg == NUL || *arg == ' '))
  3662.                 {
  3663.                 STRCPY(errbuf, ":help");
  3664.                 save_arg = arg;
  3665.                 arg = errbuf;
  3666.                 }
  3667.                 /*
  3668.                  * Convert 'whichwrap' number to string, for
  3669.                  * backwards compatibility with Vim 3.0.
  3670.                  * Misuse errbuf[] for the resulting string.
  3671.                  */
  3672.                 else if (varp == (char_u *)&p_ww && isdigit(*arg))
  3673.                 {
  3674.                 *errbuf = NUL;
  3675.                 i = getdigits(&arg);
  3676.                 if (i & 1)
  3677.                     STRCAT(errbuf, "b,");
  3678.                 if (i & 2)
  3679.                     STRCAT(errbuf, "s,");
  3680.                 if (i & 4)
  3681.                     STRCAT(errbuf, "h,l,");
  3682.                 if (i & 8)
  3683.                     STRCAT(errbuf, "<,>,");
  3684.                 if (i & 16)
  3685.                     STRCAT(errbuf, "[,],");
  3686.                 if (*errbuf != NUL)    /* remove trailing , */
  3687.                     errbuf[STRLEN(errbuf) - 1] = NUL;
  3688.                 save_arg = arg;
  3689.                 arg = errbuf;
  3690.                 }
  3691.                 /*
  3692.                  * Remove '>' before 'dir' and 'bdir', for
  3693.                  * backwards compatibility with version 3.0
  3694.                  */
  3695.                 else if (  *arg == '>'
  3696.                     && (varp == (char_u *)&p_dir
  3697.                         || varp == (char_u *)&p_bdir))
  3698.                 {
  3699.                 ++arg;
  3700.                 }
  3701.  
  3702.                 /* When setting the local value of a global
  3703.                  * option, the old value may be the global value. */
  3704.                 if ((int)options[opt_idx].indir >= PV_BOTH
  3705.                            && (opt_flags & OPT_LOCAL))
  3706.                 origval = *(char_u **)get_varp(
  3707.                                &options[opt_idx]);
  3708.                 else
  3709.                 origval = oldval;
  3710.  
  3711.                 /*
  3712.                  * Copy the new string into allocated memory.
  3713.                  * Can't use set_string_option_direct(), because
  3714.                  * we need to remove the backslashes.
  3715.                  */
  3716.                 /* get a bit too much */
  3717.                 newlen = (unsigned)STRLEN(arg) + 1;
  3718.                 if (adding || prepending || removing)
  3719.                 newlen += (unsigned)STRLEN(origval) + 1;
  3720.                 newval = alloc(newlen);
  3721.                 if (newval == NULL)  /* out of mem, don't change */
  3722.                 break;
  3723.                 s = newval;
  3724.  
  3725.                 /*
  3726.                  * Copy the string, skip over escaped chars.
  3727.                  * For MS-DOS and WIN32 backslashes before normal
  3728.                  * file name characters are not removed, and keep
  3729.                  * backslash at start, for "\\machine\path", but
  3730.                  * do remove it for "\\\\machine\\path".
  3731.                  * The reverse is found in ExpandOldSetting().
  3732.                  */
  3733.                 while (*arg && !vim_iswhite(*arg))
  3734.                 {
  3735.                 if (*arg == '\\' && arg[1] != NUL
  3736. #ifdef BACKSLASH_IN_FILENAME
  3737.                     && !((flags & P_EXPAND)
  3738.                         && vim_isfilec(arg[1])
  3739.                         && (arg[1] != '\\'
  3740.                             || (s == newval
  3741.                             && arg[2] != '\\')))
  3742. #endif
  3743.                                     )
  3744.                     ++arg;    /* remove backslash */
  3745. #ifdef FEAT_MBYTE
  3746.                 if (has_mbyte
  3747.                     && (i = (*mb_ptr2len_check)(arg)) > 1)
  3748.                 {
  3749.                     /* copy multibyte char */
  3750.                     mch_memmove(s, arg, (size_t)i);
  3751.                     arg += i;
  3752.                     s += i;
  3753.                 }
  3754.                 else
  3755. #endif
  3756.                     *s++ = *arg++;
  3757.                 }
  3758.                 *s = NUL;
  3759.  
  3760.                 /*
  3761.                  * Expand environment variables and ~.
  3762.                  * Don't do it when adding without inserting a
  3763.                  * comma.
  3764.                  */
  3765.                 if (!(adding || prepending || removing)
  3766.                              || (flags & P_COMMA))
  3767.                 {
  3768.                 s = option_expand(opt_idx, newval);
  3769.                 if (s != NULL)
  3770.                 {
  3771.                     vim_free(newval);
  3772.                     newlen = (unsigned)STRLEN(s) + 1;
  3773.                     if (adding || prepending || removing)
  3774.                     newlen += (unsigned)STRLEN(origval) + 1;
  3775.                     newval = alloc(newlen);
  3776.                     if (newval == NULL)
  3777.                     break;
  3778.                     STRCPY(newval, s);
  3779.                 }
  3780.                 }
  3781.  
  3782.                 /* locate newval[] in origval[] when removing it
  3783.                  * and when adding to avoid duplicates */
  3784.                 i = 0;    /* init for GCC */
  3785.                 if (removing || (flags & P_NODUP))
  3786.                 {
  3787.                 i = (int)STRLEN(newval);
  3788.                 bs = 0;
  3789.                 for (s = origval; *s; ++s)
  3790.                 {
  3791.                     if ((!(flags & P_COMMA)
  3792.                         || s == origval
  3793.                         || (s[-1] == ',' && !(bs & 1)))
  3794.                         && STRNCMP(s, newval, i) == 0
  3795.                         && (!(flags & P_COMMA)
  3796.                         || s[i] == ','
  3797.                         || s[i] == NUL))
  3798.                     break;
  3799.                     /* Count backspaces.  Only a comma with an
  3800.                      * even number of backspaces before it is
  3801.                      * recognized as a separator */
  3802.                     if (s > origval && s[-1] == '\\')
  3803.                     ++bs;
  3804.                     else
  3805.                     bs = 0;
  3806.                 }
  3807.  
  3808.                 /* do not add if already there */
  3809.                 if ((adding || prepending) && *s)
  3810.                 {
  3811.                     prepending = FALSE;
  3812.                     adding = FALSE;
  3813.                     STRCPY(newval, origval);
  3814.                 }
  3815.                 }
  3816.  
  3817.                 /* concatenate the two strings; add a ',' if
  3818.                  * needed */
  3819.                 if (adding || prepending)
  3820.                 {
  3821.                 comma = ((flags & P_COMMA) && *origval);
  3822.                 if (adding)
  3823.                 {
  3824.                     i = (int)STRLEN(origval);
  3825.                     mch_memmove(newval + i + comma, newval,
  3826.                               STRLEN(newval) + 1);
  3827.                     mch_memmove(newval, origval, (size_t)i);
  3828.                 }
  3829.                 else
  3830.                 {
  3831.                     i = (int)STRLEN(newval);
  3832.                     mch_memmove(newval + i + comma, origval,
  3833.                               STRLEN(origval) + 1);
  3834.                 }
  3835.                 if (comma)
  3836.                     newval[i] = ',';
  3837.                 }
  3838.  
  3839.                 /* Remove newval[] from origval[]. (Note: "i" has
  3840.                  * been set above and is used here). */
  3841.                 if (removing)
  3842.                 {
  3843.                 STRCPY(newval, origval);
  3844.                 if (*s)
  3845.                 {
  3846.                     /* may need to remove a comma */
  3847.                     if (flags & P_COMMA)
  3848.                     {
  3849.                     if (s == origval)
  3850.                     {
  3851.                         /* include comma after string */
  3852.                         if (s[i] == ',')
  3853.                         ++i;
  3854.                     }
  3855.                     else
  3856.                     {
  3857.                         /* include comma before string */
  3858.                         --s;
  3859.                         ++i;
  3860.                     }
  3861.                     }
  3862.                     mch_memmove(newval + (s - origval), s + i,
  3863.                                STRLEN(s + i) + 1);
  3864.                 }
  3865.                 }
  3866.  
  3867.                 if (flags & P_FLAGLIST)
  3868.                 {
  3869.                 /* Remove flags that appear twice. */
  3870.                 for (s = newval; *s; ++s)
  3871.                     if ((!(flags & P_COMMA) || *s != ',')
  3872.                         && vim_strchr(s + 1, *s) != NULL)
  3873.                     {
  3874.                     STRCPY(s, s + 1);
  3875.                     --s;
  3876.                     }
  3877.                 }
  3878.  
  3879.                 if (save_arg != NULL)   /* number for 'whichwrap' */
  3880.                 arg = save_arg;
  3881.                 new_value_alloced = TRUE;
  3882.             }
  3883.  
  3884.             /* Set the new value. */
  3885.             *(char_u **)(varp) = newval;
  3886.  
  3887.             /* Handle side effects, and set the global value for
  3888.              * ":set" on local options. */
  3889.             errmsg = did_set_string_option(opt_idx, (char_u **)varp,
  3890.                 new_value_alloced, oldval, errbuf, opt_flags);
  3891.  
  3892.             /* If error detected, print the error message. */
  3893.             if (errmsg != NULL)
  3894.                 goto skip;
  3895.             }
  3896.             else        /* key code option */
  3897.             {
  3898.             char_u        *p;
  3899.  
  3900.             if (nextchar == '&')
  3901.             {
  3902.                 if (add_termcap_entry(key_name, TRUE) == FAIL)
  3903.                 errmsg = (char_u *)N_("E522: Not found in termcap");
  3904.             }
  3905.             else
  3906.             {
  3907.                 ++arg; /* jump to after the '=' or ':' */
  3908.                 for (p = arg; *p && !vim_iswhite(*p); ++p)
  3909.                 if (*p == '\\' && p[1] != NUL)
  3910.                     ++p;
  3911.                 nextchar = *p;
  3912.                 *p = NUL;
  3913.                 add_termcode(key_name, arg, FALSE);
  3914.                 *p = nextchar;
  3915.             }
  3916.             if (full_screen)
  3917.                 ttest(FALSE);
  3918.             redraw_all_later(CLEAR);
  3919.             }
  3920.         }
  3921.         if (opt_idx >= 0)
  3922.             options[opt_idx].flags |= P_WAS_SET;
  3923.         }
  3924.  
  3925. skip:
  3926.         /*
  3927.          * Advance to next argument.
  3928.          * - skip until a blank found, taking care of backslashes
  3929.          * - skip blanks
  3930.          * - skip one "=val" argument (for hidden options ":set gfn =xx")
  3931.          */
  3932.         for (i = 0; i < 2 ; ++i)
  3933.         {
  3934.         while (*arg != NUL && !vim_iswhite(*arg))
  3935.             if (*arg++ == '\\' && *arg != NUL)
  3936.             ++arg;
  3937.         arg = skipwhite(arg);
  3938.         if (*arg != '=')
  3939.             break;
  3940.         }
  3941.     }
  3942.     arg = skipwhite(arg);
  3943.  
  3944.     if (errmsg != NULL)
  3945.     {
  3946.         ++no_wait_return;    /* wait_return done below */
  3947.         EMSG(_(errmsg));    /* show error highlighted */
  3948.         MSG_PUTS(": ");
  3949.                 /* show argument normal */
  3950.         while (startarg < arg)
  3951.         startarg = msg_outtrans_one(startarg, 0);
  3952.         msg_end();        /* check for scrolling */
  3953.         --no_wait_return;
  3954.  
  3955.         return FAIL;
  3956.     }
  3957.     }
  3958.  
  3959.     return OK;
  3960. }
  3961.  
  3962.     static char_u *
  3963. illegal_char(errbuf, c)
  3964.     char_u    *errbuf;
  3965.     int        c;
  3966. {
  3967.     if (errbuf == NULL)
  3968.     return (char_u *)"";
  3969.     sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
  3970.         (char *)transchar(c));
  3971.     return errbuf;
  3972. }
  3973.  
  3974. /*
  3975.  * Convert a key name or string into a key value.
  3976.  * Used for 'wildchar' and 'cedit' options.
  3977.  */
  3978.     static int
  3979. string_to_key(arg)
  3980.     char_u    *arg;
  3981. {
  3982.     if (*arg == '<')
  3983.     return find_key_option(arg + 1);
  3984.     if (*arg == '^')
  3985.     return Ctrl_chr(arg[1]);
  3986.     return *arg;
  3987. }
  3988.  
  3989. #ifdef FEAT_CMDWIN
  3990. /*
  3991.  * Check value of 'cedit' and set cedit_key.
  3992.  * Returns NULL if value is OK, error message otherwise.
  3993.  */
  3994.     static char_u *
  3995. check_cedit()
  3996. {
  3997.     int n;
  3998.  
  3999.     if (*p_cedit == NUL)
  4000.     cedit_key = -1;
  4001.     else
  4002.     {
  4003.     n = string_to_key(p_cedit);
  4004.     if (vim_isprintc(n))
  4005.         return e_invarg;
  4006.     cedit_key = n;
  4007.     }
  4008.     return NULL;
  4009. }
  4010. #endif
  4011.  
  4012. #ifdef FEAT_TITLE
  4013. /*
  4014.  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
  4015.  * maketitle() to create and display it.
  4016.  * When switching the title or icon off, call mch_restore_title() to get
  4017.  * the old value back.
  4018.  */
  4019.     static void
  4020. did_set_title(icon)
  4021.     int        icon;        /* Did set icon instead of title */
  4022. {
  4023.     if (starting != NO_SCREEN
  4024. #ifdef FEAT_GUI
  4025.         && !gui.starting
  4026. #endif
  4027.                 )
  4028.     {
  4029.     maketitle();
  4030.     if (icon)
  4031.     {
  4032.         if (!p_icon)
  4033.         mch_restore_title(2);
  4034.     }
  4035.     else
  4036.     {
  4037.         if (!p_title)
  4038.         mch_restore_title(1);
  4039.     }
  4040.     }
  4041. }
  4042. #endif
  4043.  
  4044. /*
  4045.  * set_options_bin -  called when 'bin' changes value.
  4046.  */
  4047.     void
  4048. set_options_bin(oldval, newval, opt_flags)
  4049.     int        oldval;
  4050.     int        newval;
  4051.     int        opt_flags;    /* OPT_LOCAL and/or OPT_GLOBAL */
  4052. {
  4053.     /*
  4054.      * The option values that are changed when 'bin' changes are
  4055.      * copied when 'bin is set and restored when 'bin' is reset.
  4056.      */
  4057.     if (newval)
  4058.     {
  4059.     if (!oldval)        /* switched on */
  4060.     {
  4061.         if (!(opt_flags & OPT_GLOBAL))
  4062.         {
  4063.         curbuf->b_p_tw_nobin = curbuf->b_p_tw;
  4064.         curbuf->b_p_wm_nobin = curbuf->b_p_wm;
  4065.         curbuf->b_p_ml_nobin = curbuf->b_p_ml;
  4066.         curbuf->b_p_et_nobin = curbuf->b_p_et;
  4067.         }
  4068.         if (!(opt_flags & OPT_LOCAL))
  4069.         {
  4070.         p_tw_nobin = p_tw;
  4071.         p_wm_nobin = p_wm;
  4072.         p_ml_nobin = p_ml;
  4073.         p_et_nobin = p_et;
  4074.         }
  4075.     }
  4076.  
  4077.     if (!(opt_flags & OPT_GLOBAL))
  4078.     {
  4079.         curbuf->b_p_tw = 0;    /* no automatic line wrap */
  4080.         curbuf->b_p_wm = 0;    /* no automatic line wrap */
  4081.         curbuf->b_p_ml = 0;    /* no modelines */
  4082.         curbuf->b_p_et = 0;    /* no expandtab */
  4083.     }
  4084.     if (!(opt_flags & OPT_LOCAL))
  4085.     {
  4086.         p_tw = 0;
  4087.         p_wm = 0;
  4088.         p_ml = FALSE;
  4089.         p_et = FALSE;
  4090.         p_bin = TRUE;    /* needed when called for the "-b" argument */
  4091.     }
  4092.     }
  4093.     else if (oldval)        /* switched off */
  4094.     {
  4095.     if (!(opt_flags & OPT_GLOBAL))
  4096.     {
  4097.         curbuf->b_p_tw = curbuf->b_p_tw_nobin;
  4098.         curbuf->b_p_wm = curbuf->b_p_wm_nobin;
  4099.         curbuf->b_p_ml = curbuf->b_p_ml_nobin;
  4100.         curbuf->b_p_et = curbuf->b_p_et_nobin;
  4101.     }
  4102.     if (!(opt_flags & OPT_LOCAL))
  4103.     {
  4104.         p_tw = p_tw_nobin;
  4105.         p_wm = p_wm_nobin;
  4106.         p_ml = p_ml_nobin;
  4107.         p_et = p_et_nobin;
  4108.     }
  4109.     }
  4110. }
  4111.  
  4112. #ifdef FEAT_VIMINFO
  4113. /*
  4114.  * Find the parameter represented by the given character (eg ', :, ", or /),
  4115.  * and return its associated value in the 'viminfo' string.
  4116.  * Only works for number parameters, not for 'r' or 'n'.
  4117.  * If the parameter is not specified in the string, return -1.
  4118.  */
  4119.     int
  4120. get_viminfo_parameter(type)
  4121.     int        type;
  4122. {
  4123.     char_u  *p;
  4124.  
  4125.     p = find_viminfo_parameter(type);
  4126.     if (p != NULL && isdigit(*p))
  4127.     return atoi((char *)p);
  4128.     return -1;
  4129. }
  4130.  
  4131. /*
  4132.  * Find the parameter represented by the given character (eg ', :, ", or /) in
  4133.  * the 'viminfo' option and return a pointer to the string after it.
  4134.  * Return NULL if the parameter is not specified in the string.
  4135.  */
  4136.     char_u *
  4137. find_viminfo_parameter(type)
  4138.     int        type;
  4139. {
  4140.     char_u  *p;
  4141.  
  4142.     for (p = p_viminfo; *p; ++p)
  4143.     {
  4144.     if (*p == type)
  4145.         return p + 1;
  4146.     if (*p == 'n')            /* 'n' is always the last one */
  4147.         break;
  4148.     p = vim_strchr(p, ',');        /* skip until next ',' */
  4149.     if (p == NULL)            /* hit the end without finding parameter */
  4150.         break;
  4151.     }
  4152.     return NULL;
  4153. }
  4154. #endif
  4155.  
  4156. /*
  4157.  * Expand environment variables for some string options.
  4158.  * These string options cannot be indirect!
  4159.  * If "val" is NULL expand the current value of the option.
  4160.  * Return pointer to NameBuff, or NULL when not expanded.
  4161.  */
  4162.     static char_u *
  4163. option_expand(opt_idx, val)
  4164.     int        opt_idx;
  4165.     char_u    *val;
  4166. {
  4167.     /* if option doesn't need expansion nothing to do */
  4168.     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
  4169.     return NULL;
  4170.  
  4171.     /* If val is longer than MAXPATHL no meaningful expansion can be done,
  4172.      * expand_env() would truncate the string. */
  4173.     if (val != NULL && STRLEN(val) > MAXPATHL)
  4174.     return NULL;
  4175.  
  4176.     if (val == NULL)
  4177.     val = *(char_u **)options[opt_idx].var;
  4178.  
  4179.     /*
  4180.      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
  4181.      */
  4182.     expand_env(val, NameBuff, MAXPATHL);
  4183.     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
  4184.     return NULL;
  4185.  
  4186.     return NameBuff;
  4187. }
  4188.  
  4189. /*
  4190.  * After setting various option values: recompute variables that depend on
  4191.  * option values.
  4192.  */
  4193.     static void
  4194. didset_options()
  4195. {
  4196.     /* initialize the table for 'iskeyword' et.al. */
  4197.     (void)init_chartab();
  4198.  
  4199.     (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
  4200. #ifdef FEAT_SESSION
  4201.     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
  4202.     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
  4203. #endif
  4204. #ifdef FEAT_FOLDING
  4205.     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
  4206. #endif
  4207.     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
  4208. #ifdef FEAT_VIRTUALEDIT
  4209.     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
  4210. #endif
  4211. #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
  4212.     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
  4213. #endif
  4214. #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
  4215.     (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
  4216. #endif
  4217. #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
  4218.     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
  4219. #endif
  4220. #ifdef FEAT_CMDWIN
  4221.     /* set cedit_key */
  4222.     (void)check_cedit();
  4223. #endif
  4224. }
  4225.  
  4226. /*
  4227.  * Check for string options that are NULL (normally only termcap options).
  4228.  */
  4229.     void
  4230. check_options()
  4231. {
  4232.     int        opt_idx;
  4233.  
  4234.     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
  4235.     if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
  4236.         check_string_option((char_u **)get_varp(&(options[opt_idx])));
  4237. }
  4238.  
  4239. /*
  4240.  * Check string options in a buffer for NULL value.
  4241.  */
  4242.     void
  4243. check_buf_options(buf)
  4244.     buf_T    *buf;
  4245. {
  4246. #if defined(FEAT_QUICKFIX)
  4247.     check_string_option(&buf->b_p_bh);
  4248.     check_string_option(&buf->b_p_bt);
  4249. #endif
  4250. #ifdef FEAT_MBYTE
  4251.     check_string_option(&buf->b_p_fenc);
  4252. #endif
  4253.     check_string_option(&buf->b_p_ff);
  4254. #ifdef FEAT_FIND_ID
  4255.     check_string_option(&buf->b_p_def);
  4256.     check_string_option(&buf->b_p_inc);
  4257. # ifdef FEAT_EVAL
  4258.     check_string_option(&buf->b_p_inex);
  4259. # endif
  4260. #endif
  4261. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  4262.     check_string_option(&buf->b_p_inde);
  4263.     check_string_option(&buf->b_p_indk);
  4264. #endif
  4265. #ifdef FEAT_CRYPT
  4266.     check_string_option(&buf->b_p_key);
  4267. #endif
  4268.     check_string_option(&buf->b_p_kp);
  4269.     check_string_option(&buf->b_p_mps);
  4270.     check_string_option(&buf->b_p_fo);
  4271.     check_string_option(&buf->b_p_isk);
  4272. #ifdef FEAT_COMMENTS
  4273.     check_string_option(&buf->b_p_com);
  4274. #endif
  4275. #ifdef FEAT_FOLDING
  4276.     check_string_option(&buf->b_p_cms);
  4277. #endif
  4278.     check_string_option(&buf->b_p_nf);
  4279. #ifdef FEAT_SYN_HL
  4280.     check_string_option(&buf->b_p_syn);
  4281. #endif
  4282. #ifdef FEAT_SEARCHPATH
  4283.     check_string_option(&buf->b_p_sua);
  4284. #endif
  4285. #ifdef FEAT_CINDENT
  4286.     check_string_option(&buf->b_p_cink);
  4287.     check_string_option(&buf->b_p_cino);
  4288. #endif
  4289. #ifdef FEAT_AUTOCMD
  4290.     check_string_option(&buf->b_p_ft);
  4291. #endif
  4292. #ifdef FEAT_OSFILETYPE
  4293.     check_string_option(&buf->b_p_oft);
  4294. #endif
  4295. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  4296.     check_string_option(&buf->b_p_cinw);
  4297. #endif
  4298. #ifdef FEAT_INS_EXPAND
  4299.     check_string_option(&buf->b_p_cpt);
  4300. #endif
  4301. #ifdef FEAT_KEYMAP
  4302.     check_string_option(&buf->b_p_keymap);
  4303. #endif
  4304. #ifdef FEAT_QUICKFIX
  4305.     check_string_option(&buf->b_p_gp);
  4306.     check_string_option(&buf->b_p_mp);
  4307.     check_string_option(&buf->b_p_efm);
  4308. #endif
  4309.     check_string_option(&buf->b_p_ep);
  4310.     check_string_option(&buf->b_p_path);
  4311.     check_string_option(&buf->b_p_tags);
  4312. #ifdef FEAT_INS_EXPAND
  4313.     check_string_option(&buf->b_p_dict);
  4314.     check_string_option(&buf->b_p_tsr);
  4315. #endif
  4316. }
  4317.  
  4318. /*
  4319.  * Free the string allocated for an option.
  4320.  * Checks for the string being empty_option. This may happen if we're out of
  4321.  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
  4322.  * check_options().
  4323.  * Does NOT check for P_ALLOCED flag!
  4324.  */
  4325.     void
  4326. free_string_option(p)
  4327.     char_u    *p;
  4328. {
  4329.     if (p != empty_option)
  4330.     vim_free(p);
  4331. }
  4332.  
  4333.     void
  4334. clear_string_option(pp)
  4335.     char_u    **pp;
  4336. {
  4337.     if (*pp != empty_option)
  4338.     vim_free(*pp);
  4339.     *pp = empty_option;
  4340. }
  4341.  
  4342.     static void
  4343. check_string_option(pp)
  4344.     char_u    **pp;
  4345. {
  4346.     if (*pp == NULL)
  4347.     *pp = empty_option;
  4348. }
  4349.  
  4350. /*
  4351.  * Mark a terminal option as allocated, found by a pointer into term_strings[].
  4352.  */
  4353.     void
  4354. set_term_option_alloced(p)
  4355.     char_u **p;
  4356. {
  4357.     int        opt_idx;
  4358.  
  4359.     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
  4360.     if (options[opt_idx].var == (char_u *)p)
  4361.     {
  4362.         options[opt_idx].flags |= P_ALLOCED;
  4363.         return;
  4364.     }
  4365.     return; /* cannot happen: didn't find it! */
  4366. }
  4367.  
  4368. /*
  4369.  * Set a string option to a new value (without checking the effect).
  4370.  * The string is copied into allocated memory.
  4371.  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
  4372.  */
  4373.     void
  4374. set_string_option_direct(name, opt_idx, val, opt_flags)
  4375.     char_u    *name;
  4376.     int        opt_idx;
  4377.     char_u    *val;
  4378.     int        opt_flags;    /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
  4379. {
  4380.     char_u    *s;
  4381.     char_u    **varp;
  4382.     int        both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
  4383.  
  4384.     if (opt_idx == -1)        /* use name */
  4385.     {
  4386.     opt_idx = findoption(name);
  4387.     if (opt_idx == -1)    /* not found (should not happen) */
  4388.         return;
  4389.     }
  4390.  
  4391.     if (options[opt_idx].var == NULL)    /* can't set hidden option */
  4392.     return;
  4393.  
  4394.     s = vim_strsave(val);
  4395.     if (s != NULL)
  4396.     {
  4397.     varp = (char_u **)get_varp_scope(&(options[opt_idx]),
  4398.                            both ? OPT_LOCAL : opt_flags);
  4399.     if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
  4400.         free_string_option(*varp);
  4401.     *varp = s;
  4402.  
  4403.     /* For buffer/window local option may also set the global value. */
  4404.     if (both)
  4405.         set_string_option_global(opt_idx, varp);
  4406.  
  4407.     options[opt_idx].flags |= P_ALLOCED;
  4408.  
  4409.     /* When setting both values of a global option with a local value,
  4410.      * make the local value empty, so that the global value is used. */
  4411.     if ((int)options[opt_idx].indir >= PV_BOTH && both)
  4412.     {
  4413.         free_string_option(*varp);
  4414.         *varp = empty_option;
  4415.     }
  4416.     }
  4417. }
  4418.  
  4419. /*
  4420.  * Set global value for string option when it's a local option.
  4421.  */
  4422.     static void
  4423. set_string_option_global(opt_idx, varp)
  4424.     int        opt_idx;    /* option index */
  4425.     char_u    **varp;        /* pointer to option variable */
  4426. {
  4427.     char_u    **p, *s;
  4428.  
  4429.     /* the global value is always allocated */
  4430.     if (options[opt_idx].var == VAR_WIN)
  4431.     p = (char_u **)GLOBAL_WO(varp);
  4432.     else
  4433.     p = (char_u **)options[opt_idx].var;
  4434.     if (options[opt_idx].indir != PV_NONE
  4435.         && p != varp
  4436.         && (s = vim_strsave(*varp)) != NULL)
  4437.     {
  4438.     free_string_option(*p);
  4439.     *p = s;
  4440.     }
  4441. }
  4442.  
  4443. /*
  4444.  * Set a string option to a new value, and handle the effects.
  4445.  */
  4446.     static void
  4447. set_string_option(opt_idx, value, opt_flags)
  4448.     int        opt_idx;
  4449.     char_u    *value;
  4450.     int        opt_flags;    /* OPT_LOCAL and/or OPT_GLOBAL */
  4451. {
  4452.     char_u    *s;
  4453.     char_u    **varp;
  4454.     char_u    *oldval;
  4455.  
  4456.     if (options[opt_idx].var == NULL)    /* don't set hidden option */
  4457.     return;
  4458.  
  4459.     s = vim_strsave(value);
  4460.     if (s != NULL)
  4461.     {
  4462.     varp = (char_u **)get_varp_scope(&(options[opt_idx]),
  4463.         (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
  4464.             ? ((int)options[opt_idx].indir >= PV_BOTH
  4465.             ? OPT_GLOBAL : OPT_LOCAL)
  4466.             : opt_flags);
  4467.     oldval = *varp;
  4468.     *varp = s;
  4469.     options[opt_idx].flags |= P_WAS_SET;
  4470.     (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
  4471.                                    opt_flags);
  4472.     }
  4473. }
  4474.  
  4475. /*
  4476.  * Handle string options that need some action to perform when changed.
  4477.  * Returns NULL for success, or an error message for an error.
  4478.  */
  4479.     static char_u *
  4480. did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
  4481.                                     opt_flags)
  4482.     int        opt_idx;        /* index in options[] table */
  4483.     char_u    **varp;            /* pointer to the option variable */
  4484.     int        new_value_alloced;    /* new value was allocated */
  4485.     char_u    *oldval;        /* previous value of the option */
  4486.     char_u    *errbuf;        /* buffer for errors, or NULL */
  4487.     int        opt_flags;        /* OPT_LOCAL and/or OPT_GLOBAL */
  4488. {
  4489.     char_u    *errmsg = NULL;
  4490.     char_u    *s, *p;
  4491.     int        did_chartab = FALSE;
  4492.     char_u    **gvarp;
  4493.  
  4494.     /* Get the global option to compare with, otherwise we would have to check
  4495.      * two values for all local options. */
  4496.     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
  4497.  
  4498.     /* Disallow changing some options from secure mode */
  4499.     if ((secure
  4500. #ifdef HAVE_SANDBOX
  4501.         || sandbox != 0
  4502. #endif
  4503.         ) && (options[opt_idx].flags & P_SECURE))
  4504.     {
  4505.     errmsg = e_secure;
  4506.     }
  4507.  
  4508.     /* 'term' */
  4509.     else if (varp == &T_NAME)
  4510.     {
  4511.     if (T_NAME[0] == NUL)
  4512.         errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
  4513. #ifdef FEAT_GUI
  4514.     if (gui.in_use)
  4515.         errmsg = (char_u *)N_("E530: Cannot change term in GUI");
  4516.     else if (term_is_gui(T_NAME))
  4517.         errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
  4518. #endif
  4519.     else if (set_termname(T_NAME) == FAIL)
  4520.         errmsg = (char_u *)N_("E522: Not found in termcap");
  4521.     else
  4522.         /* Screen colors may have changed. */
  4523.         redraw_later_clear();
  4524.     }
  4525.  
  4526.     /* 'backupcopy' */
  4527.     else if (varp == &p_bkc)
  4528.     {
  4529.     if (check_opt_strings(p_bkc, p_bkc_values, FALSE) != OK)
  4530.         errmsg = e_invarg;
  4531.     }
  4532.  
  4533.     /* 'backupext' and 'patchmode' */
  4534.     else if (varp == &p_bex || varp == &p_pm)
  4535.     {
  4536.     if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
  4537.              *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
  4538.         errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
  4539.     }
  4540.  
  4541.     /*
  4542.      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
  4543.      * If the new option is invalid, use old value.  'lisp' option: refill
  4544.      * chartab[] for '-' char
  4545.      */
  4546.     else if (  varp == &p_isi
  4547.         || varp == &(curbuf->b_p_isk)
  4548.         || varp == &p_isp
  4549.         || varp == &p_isf)
  4550.     {
  4551.     if (init_chartab() == FAIL)
  4552.     {
  4553.         did_chartab = TRUE;        /* need to restore it below */
  4554.         errmsg = e_invarg;        /* error in value */
  4555.     }
  4556.     }
  4557.  
  4558.     /* 'helpfile' */
  4559.     else if (varp == &p_hf)
  4560.     {
  4561.     /* May compute new values for $VIM and $VIMRUNTIME */
  4562.     if (didset_vim)
  4563.     {
  4564.         vim_setenv((char_u *)"VIM", (char_u *)"");
  4565.         didset_vim = FALSE;
  4566.     }
  4567.     if (didset_vimruntime)
  4568.     {
  4569.         vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
  4570.         didset_vimruntime = FALSE;
  4571.     }
  4572.     }
  4573.  
  4574.     /* 'highlight' */
  4575.     else if (varp == &p_hl)
  4576.     {
  4577.     if (highlight_changed() == FAIL)
  4578.         errmsg = e_invarg;    /* invalid flags */
  4579.     }
  4580.  
  4581.     /* 'nrformats' */
  4582.     else if (gvarp == &p_nf)
  4583.     {
  4584.     if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
  4585.         errmsg = e_invarg;
  4586.     }
  4587.  
  4588. #ifdef FEAT_SESSION
  4589.     /* 'sessionoptions' */
  4590.     else if (varp == &p_ssop)
  4591.     {
  4592.     if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
  4593.         errmsg = e_invarg;
  4594.     if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
  4595.     {
  4596.         /* Don't allow both "sesdir" and "curdir". */
  4597.         (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
  4598.         errmsg = e_invarg;
  4599.     }
  4600.     }
  4601.     /* 'viewoptions' */
  4602.     else if (varp == &p_vop)
  4603.     {
  4604.     if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
  4605.         errmsg = e_invarg;
  4606.     }
  4607. #endif
  4608.  
  4609.     /* 'scrollopt' */
  4610. #ifdef FEAT_SCROLLBIND
  4611.     else if (varp == &p_sbo)
  4612.     {
  4613.     if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
  4614.         errmsg = e_invarg;
  4615.     }
  4616. #endif
  4617.  
  4618.     /* 'ambiwidth' */
  4619. #ifdef FEAT_MBYTE
  4620.     else if (varp == &p_ambw)
  4621.     {
  4622.     if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
  4623.         errmsg = e_invarg;
  4624.     }
  4625. #endif
  4626.  
  4627.     /* 'background' */
  4628.     else if (varp == &p_bg)
  4629.     {
  4630.     if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
  4631.     {
  4632. #ifdef FEAT_EVAL
  4633.         int dark = (*p_bg == 'd');
  4634. #endif
  4635.  
  4636.         init_highlight(FALSE, FALSE);
  4637.  
  4638. #ifdef FEAT_EVAL
  4639.         if (dark != (*p_bg == 'd')
  4640.               && get_var_value((char_u *)"g:colors_name") != NULL)
  4641.         {
  4642.         /* The color scheme must have set 'background' back to another
  4643.          * value, that's not what we want here.  Disable the color
  4644.          * scheme and set the colors again. */
  4645.         do_unlet((char_u *)"g:colors_name");
  4646.         free_string_option(p_bg);
  4647.         p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
  4648.         check_string_option(&p_bg);
  4649.         init_highlight(FALSE, FALSE);
  4650.         }
  4651. #endif
  4652.     }
  4653.     else
  4654.         errmsg = e_invarg;
  4655.     }
  4656.  
  4657.     /* 'wildmode' */
  4658.     else if (varp == &p_wim)
  4659.     {
  4660.     if (check_opt_wim() == FAIL)
  4661.         errmsg = e_invarg;
  4662.     }
  4663.  
  4664. #ifdef FEAT_WAK
  4665.     /* 'winaltkeys' */
  4666.     else if (varp == &p_wak)
  4667.     {
  4668.     if (*p_wak == NUL
  4669.         || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
  4670.         errmsg = e_invarg;
  4671. # ifdef FEAT_MENU
  4672. #  ifdef FEAT_GUI_MOTIF
  4673.     else if (gui.in_use)
  4674.         gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
  4675. #  else
  4676. #   ifdef FEAT_GUI_GTK
  4677.     else if (gui.in_use)
  4678.         gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
  4679. #   endif
  4680. #  endif
  4681. # endif
  4682.     }
  4683. #endif
  4684.  
  4685. #ifdef FEAT_AUTOCMD
  4686.     /* 'eventignore' */
  4687.     else if (varp == &p_ei)
  4688.     {
  4689.     if (check_ei() == FAIL)
  4690.         errmsg = e_invarg;
  4691.     }
  4692. #endif
  4693.  
  4694. #ifdef FEAT_MBYTE
  4695.     /* 'encoding' and 'fileencoding' */
  4696.     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
  4697.     {
  4698.     if (varp == &curbuf->b_p_fenc && !curbuf->b_p_ma)
  4699.         errmsg = e_modifiable;
  4700.     else
  4701.     {
  4702.         /* canonize the value, so that STRCMP() can be used on it */
  4703.         p = enc_canonize(*varp);
  4704.         if (p != NULL)
  4705.         {
  4706.         vim_free(*varp);
  4707.         *varp = p;
  4708.         }
  4709.         if (varp == &p_enc)
  4710.         {
  4711.         errmsg = mb_init();
  4712. # ifdef FEAT_TITLE
  4713.         need_maketitle = TRUE;
  4714. # endif
  4715.         }
  4716.     }
  4717.  
  4718. # if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
  4719.     if (errmsg == NULL && varp == &p_tenc && gui.in_use)
  4720.     {
  4721.         /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
  4722.         if (STRCMP(p_tenc, "utf-8") != 0)
  4723.         errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
  4724.     }
  4725. # endif
  4726.  
  4727.     if (errmsg == NULL)
  4728.     {
  4729. # ifdef FEAT_KEYMAP
  4730.         /* When 'keymap' is used and 'encoding' changes, reload the keymap
  4731.          * (with another encoding). */
  4732.         if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
  4733.         (void)keymap_init();
  4734. # endif
  4735.  
  4736.         /* When 'termencoding' is not empty and 'encoding' changes or when
  4737.          * 'termencoding' changes, need to setup for keyboard input and
  4738.          * display output conversion. */
  4739.         if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
  4740.         {
  4741.         convert_setup(&input_conv, p_tenc, p_enc);
  4742.         convert_setup(&output_conv, p_enc, p_tenc);
  4743.         }
  4744.     }
  4745.     }
  4746. #endif
  4747.  
  4748. #if defined(FEAT_POSTSCRIPT)
  4749.     else if (varp == &p_penc)
  4750.     {
  4751.     /* Canonize printencoding if VIM standard one */
  4752.     p = enc_canonize(p_penc);
  4753.     if (p != NULL)
  4754.     {
  4755.         vim_free(p_penc);
  4756.         p_penc = p;
  4757.     }
  4758.     else
  4759.     {
  4760.         /* Ensure lower case and '-' for '_' */
  4761.         for (s = p_penc; *s != NUL; s++)
  4762.         {
  4763.         if (*s == '_')
  4764.             *s = '-';
  4765.         else
  4766.             *s = TOLOWER_ASC(*s);
  4767.         }
  4768.     }
  4769.     }
  4770. #endif
  4771.  
  4772. #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
  4773.     else if (varp == &p_imak)
  4774.     {
  4775.     if (!im_xim_isvalid_imactivate())
  4776.         errmsg = e_invarg;
  4777.     }
  4778. #endif
  4779.  
  4780. #ifdef FEAT_KEYMAP
  4781.     else if (varp == &curbuf->b_p_keymap)
  4782.     {
  4783.     /* load or unload key mapping tables */
  4784.     errmsg = keymap_init();
  4785.  
  4786.     /* When successfully installed a new keymap switch on using it. */
  4787.     if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
  4788.     {
  4789.         curbuf->b_p_iminsert = B_IMODE_LMAP;
  4790.         if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
  4791.         curbuf->b_p_imsearch = B_IMODE_LMAP;
  4792.         set_iminsert_global();
  4793.         set_imsearch_global();
  4794. # ifdef FEAT_WINDOWS
  4795.         status_redraw_curbuf();
  4796. # endif
  4797.     }
  4798.     }
  4799. #endif
  4800.  
  4801.     /* 'fileformat' */
  4802.     else if (gvarp == &p_ff)
  4803.     {
  4804.     if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
  4805.         errmsg = e_modifiable;
  4806.     else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
  4807.         errmsg = e_invarg;
  4808.     else
  4809.     {
  4810.         /* may also change 'textmode' */
  4811.         if (get_fileformat(curbuf) == EOL_DOS)
  4812.         curbuf->b_p_tx = TRUE;
  4813.         else
  4814.         curbuf->b_p_tx = FALSE;
  4815. #ifdef FEAT_TITLE
  4816.         need_maketitle = TRUE;
  4817. #endif
  4818.     }
  4819.     }
  4820.  
  4821.     /* 'fileformats' */
  4822.     else if (varp == &p_ffs)
  4823.     {
  4824.     if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
  4825.         errmsg = e_invarg;
  4826.     else
  4827.     {
  4828.         /* also change 'textauto' */
  4829.         if (*p_ffs == NUL)
  4830.         p_ta = FALSE;
  4831.         else
  4832.         p_ta = TRUE;
  4833.     }
  4834.     }
  4835.  
  4836. #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
  4837.     /* 'cryptkey' */
  4838.     else if (gvarp == &p_key)
  4839.     {
  4840.     /* Make sure the ":set" command doesn't show the new value in the
  4841.      * history. */
  4842.     remove_key_from_history();
  4843.     }
  4844. #endif
  4845.  
  4846.     /* 'matchpairs' */
  4847.     else if (gvarp == &p_mps)
  4848.     {
  4849.     /* Check for "x:y,x:y" */
  4850.     for (p = *varp; *p; p += 4)
  4851.     {
  4852.         if (!p[0] || p[1] != ':' || !p[2] || (p[3] && p[3] != ','))
  4853.         {
  4854.         errmsg = e_invarg;
  4855.         break;
  4856.         }
  4857.         if (!p[3])
  4858.         break;
  4859.     }
  4860.     }
  4861.  
  4862. #ifdef FEAT_COMMENTS
  4863.     /* 'comments' */
  4864.     else if (gvarp == &p_com)
  4865.     {
  4866.     for (s = *varp; *s; )
  4867.     {
  4868.         while (*s && *s != ':')
  4869.         {
  4870.         if (vim_strchr((char_u *)COM_ALL, *s) == NULL
  4871.                          && !isdigit(*s) && *s != '-')
  4872.         {
  4873.             errmsg = illegal_char(errbuf, *s);
  4874.             break;
  4875.         }
  4876.         ++s;
  4877.         }
  4878.         if (*s++ == NUL)
  4879.         errmsg = (char_u *)N_("E524: Missing colon");
  4880.         else if (*s == ',' || *s == NUL)
  4881.         errmsg = (char_u *)N_("E525: Zero length string");
  4882.         if (errmsg != NULL)
  4883.         break;
  4884.         while (*s && *s != ',')
  4885.         {
  4886.         if (*s == '\\' && s[1] != NUL)
  4887.             ++s;
  4888.         ++s;
  4889.         }
  4890.         s = skip_to_option_part(s);
  4891.     }
  4892.     }
  4893. #endif
  4894.  
  4895.     /* 'listchars' */
  4896.     else if (varp == &p_lcs)
  4897.     {
  4898.     errmsg = set_chars_option(varp);
  4899.     }
  4900.  
  4901. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  4902.     /* 'fillchars' */
  4903.     else if (varp == &p_fcs)
  4904.     {
  4905.     errmsg = set_chars_option(varp);
  4906.     }
  4907. #endif
  4908.  
  4909. #ifdef FEAT_CMDWIN
  4910.     /* 'cedit' */
  4911.     else if (varp == &p_cedit)
  4912.     {
  4913.     errmsg = check_cedit();
  4914.     }
  4915. #endif
  4916.  
  4917. #ifdef FEAT_VIMINFO
  4918.     /* 'viminfo' */
  4919.     else if (varp == &p_viminfo)
  4920.     {
  4921.     for (s = p_viminfo; *s;)
  4922.     {
  4923.         /* Check it's a valid character */
  4924.         if (vim_strchr((char_u *)"!\"%'/:@cfhnr", *s) == NULL)
  4925.         {
  4926.         errmsg = illegal_char(errbuf, *s);
  4927.         break;
  4928.         }
  4929.         if (*s == 'n')    /* name is always last one */
  4930.         {
  4931.         break;
  4932.         }
  4933.         else if (*s == 'r') /* skip until next ',' */
  4934.         {
  4935.         while (*++s && *s != ',')
  4936.             ;
  4937.         }
  4938.         else if (*s == '%' || *s == '!' || *s == 'h' || *s == 'c')
  4939.         ++s;        /* no extra chars */
  4940.         else        /* must have a number */
  4941.         {
  4942.         while (isdigit(*++s))
  4943.             ;
  4944.  
  4945.         if (!isdigit(*(s - 1)))
  4946.         {
  4947.             if (errbuf != NULL)
  4948.             {
  4949.             sprintf((char *)errbuf, _("E526: Missing number after <%s>"),
  4950.                             transchar_byte(*(s - 1)));
  4951.             errmsg = errbuf;
  4952.             }
  4953.             else
  4954.             errmsg = (char_u *)"";
  4955.             break;
  4956.         }
  4957.         }
  4958.         if (*s == ',')
  4959.         ++s;
  4960.         else if (*s)
  4961.         {
  4962.         if (errbuf != NULL)
  4963.             errmsg = (char_u *)N_("E527: Missing comma");
  4964.         else
  4965.             errmsg = (char_u *)"";
  4966.         break;
  4967.         }
  4968.     }
  4969.     if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
  4970.         errmsg = (char_u *)N_("E528: Must specify a ' value");
  4971.     }
  4972. #endif /* FEAT_VIMINFO */
  4973.  
  4974.     /* terminal options */
  4975.     else if (istermoption(&options[opt_idx]) && full_screen)
  4976.     {
  4977.     /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
  4978.     if (varp == &T_CCO)
  4979.     {
  4980.         t_colors = atoi((char *)T_CCO);
  4981.         if (t_colors <= 1)
  4982.         {
  4983.         if (new_value_alloced)
  4984.             vim_free(T_CCO);
  4985.         T_CCO = empty_option;
  4986.         }
  4987.         /* We now have a different color setup, initialize it again. */
  4988.         init_highlight(TRUE, FALSE);
  4989.     }
  4990.     ttest(FALSE);
  4991.     if (varp == &T_ME)
  4992.     {
  4993.         out_str(T_ME);
  4994.         redraw_later(CLEAR);
  4995. #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
  4996.         /* Since t_me has been set, this probably means that the user
  4997.          * wants to use this as default colors.  Need to reset default
  4998.          * background/foreground colors. */
  4999.         mch_set_normal_colors();
  5000. #endif
  5001.     }
  5002.     }
  5003.  
  5004. #ifdef FEAT_LINEBREAK
  5005.     /* 'showbreak' */
  5006.     else if (varp == &p_sbr)
  5007.     {
  5008.     for (s = p_sbr; *s; )
  5009.     {
  5010.         if (ptr2cells(s) != 1)
  5011.         errmsg = (char_u *)N_("E595: contains unprintable or wide character");
  5012. # ifdef FEAT_MBYTE
  5013.         if (has_mbyte)
  5014.         s += (*mb_ptr2len_check)(s);
  5015.         else
  5016. # endif
  5017.         ++s;
  5018.     }
  5019.     }
  5020. #endif
  5021.  
  5022. #ifdef FEAT_GUI
  5023.     /* 'guifont' */
  5024.     else if (varp == &p_guifont)
  5025.     {
  5026.     if (gui.in_use)
  5027.     {
  5028.         p = p_guifont;
  5029. # ifdef FEAT_GUI_GTK
  5030.         /*
  5031.          * Put up a font dialog and let the user select a new value.
  5032.          * If this is cancelled go back to the old value but don't
  5033.          * give an error message.
  5034.          */
  5035.         if (STRCMP(p, "*") == 0)
  5036.         {
  5037.         p = gui_mch_font_dialog(oldval);
  5038.  
  5039.         if (new_value_alloced)
  5040.             free_string_option(p_guifont);
  5041.  
  5042.         p_guifont = (p != NULL) ? p : vim_strsave(oldval);
  5043.         new_value_alloced = TRUE;
  5044.         }
  5045. # endif
  5046.         if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
  5047.         {
  5048. # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
  5049.         if (STRCMP(p_guifont, "*") == 0)
  5050.         {
  5051.             /* Dialog was cancelled: Keep the old value without giving
  5052.              * an error message. */
  5053.             if (new_value_alloced)
  5054.             free_string_option(p_guifont);
  5055.             p_guifont = vim_strsave(oldval);
  5056.             new_value_alloced = TRUE;
  5057.         }
  5058.         else
  5059. # endif
  5060.             errmsg = (char_u *)N_("E596: Invalid font(s)");
  5061.         }
  5062.     }
  5063.     }
  5064. # ifdef FEAT_XFONTSET
  5065.     else if (varp == &p_guifontset)
  5066.     {
  5067.     if (STRCMP(p_guifontset, "*") == 0)
  5068.         errmsg = (char_u *)N_("E597: can't select fontset");
  5069.     else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
  5070.         errmsg = (char_u *)N_("E598: Invalid fontset");
  5071.     }
  5072. # endif
  5073. # ifdef FEAT_MBYTE
  5074.     else if (varp == &p_guifontwide)
  5075.     {
  5076.     if (STRCMP(p_guifontwide, "*") == 0)
  5077.         errmsg = (char_u *)N_("E533: can't select wide font");
  5078.     else if (gui_get_wide_font() == FAIL)
  5079.         errmsg = (char_u *)N_("E534: Invalid wide font");
  5080.     }
  5081. # endif
  5082. #endif
  5083.  
  5084. #ifdef CURSOR_SHAPE
  5085.     /* 'guicursor' */
  5086.     else if (varp == &p_guicursor)
  5087.     errmsg = parse_shape_opt(SHAPE_CURSOR);
  5088. #endif
  5089.  
  5090. #ifdef FEAT_MOUSESHAPE
  5091.     /* 'mouseshape' */
  5092.     else if (varp == &p_mouseshape)
  5093.     {
  5094.     errmsg = parse_shape_opt(SHAPE_MOUSE);
  5095.     update_mouseshape(-1);
  5096.     }
  5097. #endif
  5098.  
  5099. #ifdef FEAT_PRINTER
  5100.     else if (varp == &p_popt)
  5101.     errmsg = parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
  5102. #endif
  5103.  
  5104. #ifdef FEAT_LANGMAP
  5105.     /* 'langmap' */
  5106.     else if (varp == &p_langmap)
  5107.     langmap_set();
  5108. #endif
  5109.  
  5110. #ifdef FEAT_LINEBREAK
  5111.     /* 'breakat' */
  5112.     else if (varp == &p_breakat)
  5113.     fill_breakat_flags();
  5114. #endif
  5115.  
  5116. #ifdef FEAT_TITLE
  5117.     /* 'titlestring' and 'iconstring' */
  5118.     else if (varp == &p_titlestring || varp == &p_iconstring)
  5119.     {
  5120. # ifdef FEAT_STL_OPT
  5121.     int    flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
  5122.  
  5123.     /* NULL => statusline syntax */
  5124.     if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
  5125.         stl_syntax |= flagval;
  5126.     else
  5127.         stl_syntax &= ~flagval;
  5128. # endif
  5129.     did_set_title(varp == &p_iconstring);
  5130.  
  5131.     }
  5132. #endif
  5133.  
  5134. #ifdef FEAT_GUI
  5135.     /* 'guioptions' */
  5136.     else if (varp == &p_go)
  5137.     gui_init_which_components(oldval);
  5138. #endif
  5139.  
  5140. #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
  5141.     /* 'ttymouse' */
  5142.     else if (varp == &p_ttym)
  5143.     {
  5144.     if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
  5145.         errmsg = e_invarg;
  5146.     else
  5147.         check_mouse_termcode();
  5148.     }
  5149. #endif
  5150.  
  5151. #ifdef FEAT_VISUAL
  5152.     /* 'selection' */
  5153.     else if (varp == &p_sel)
  5154.     {
  5155.     if (*p_sel == NUL
  5156.         || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
  5157.         errmsg = e_invarg;
  5158.     }
  5159.  
  5160.     /* 'selectmode' */
  5161.     else if (varp == &p_slm)
  5162.     {
  5163.     if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
  5164.         errmsg = e_invarg;
  5165.     }
  5166. #endif
  5167.  
  5168. #ifdef FEAT_BROWSE
  5169.     /* 'browsedir' */
  5170.     else if (varp == &p_bsdir)
  5171.     {
  5172.     if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
  5173.         && !mch_isdir(p_bsdir))
  5174.         errmsg = e_invarg;
  5175.     }
  5176. #endif
  5177.  
  5178. #ifdef FEAT_VISUAL
  5179.     /* 'keymodel' */
  5180.     else if (varp == &p_km)
  5181.     {
  5182.     if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
  5183.         errmsg = e_invarg;
  5184.     else
  5185.     {
  5186.         km_stopsel = (vim_strchr(p_km, 'o') != NULL);
  5187.         km_startsel = (vim_strchr(p_km, 'a') != NULL);
  5188.     }
  5189.     }
  5190. #endif
  5191.  
  5192.     /* 'mousemodel' */
  5193.     else if (varp == &p_mousem)
  5194.     {
  5195.     if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
  5196.         errmsg = e_invarg;
  5197. #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
  5198.     else if (*p_mousem != *oldval)
  5199.         /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
  5200.          * to create or delete the popup menus. */
  5201.         gui_motif_update_mousemodel(root_menu);
  5202. #endif
  5203.     }
  5204.  
  5205.     /* 'switchbuf' */
  5206.     else if (varp == &p_swb)
  5207.     {
  5208.     if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
  5209.         errmsg = e_invarg;
  5210.     }
  5211.  
  5212.     /* 'debug' */
  5213.     else if (varp == &p_debug)
  5214.     {
  5215.     if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
  5216.         errmsg = e_invarg;
  5217.     }
  5218.  
  5219.     /* 'display' */
  5220.     else if (varp == &p_dy)
  5221.     {
  5222.     if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
  5223.         errmsg = e_invarg;
  5224.     else
  5225.         (void)init_chartab();
  5226.  
  5227.     }
  5228.  
  5229. #ifdef FEAT_VERTSPLIT
  5230.     /* 'eadirection' */
  5231.     else if (varp == &p_ead)
  5232.     {
  5233.     if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
  5234.         errmsg = e_invarg;
  5235.     }
  5236. #endif
  5237.  
  5238. #ifdef FEAT_CLIPBOARD
  5239.     /* 'clipboard' */
  5240.     else if (varp == &p_cb)
  5241.     errmsg = check_clipboard_option();
  5242. #endif
  5243.  
  5244. #ifdef FEAT_AUTOCMD
  5245. # ifdef FEAT_SYN_HL
  5246.     /* When 'syntax' is set, load the syntax of that name */
  5247.     else if (varp == &(curbuf->b_p_syn))
  5248.     {
  5249.     apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
  5250.                          curbuf->b_fname, TRUE, curbuf);
  5251.     }
  5252. # endif
  5253.  
  5254.     /* When 'filetype' is set, trigger the FileType autocommands of that name */
  5255.     else if (varp == &(curbuf->b_p_ft))
  5256.     {
  5257.     did_filetype = TRUE;
  5258.     apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
  5259.                          curbuf->b_fname, TRUE, curbuf);
  5260.     }
  5261. #endif
  5262.  
  5263. #ifdef FEAT_QUICKFIX
  5264.     /* When 'bufhidden' is set, check for valid value. */
  5265.     else if (gvarp == &p_bh)
  5266.     {
  5267.     if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
  5268.         errmsg = e_invarg;
  5269.     }
  5270.  
  5271.     /* When 'buftype' is set, check for valid value. */
  5272.     else if (gvarp == &p_bt)
  5273.     {
  5274.     if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
  5275.         errmsg = e_invarg;
  5276.     else
  5277.     {
  5278. # ifdef FEAT_WINDOWS
  5279.         if (curwin->w_status_height)
  5280.         {
  5281.         curwin->w_redr_status = TRUE;
  5282.         redraw_later(VALID);
  5283.         }
  5284. # endif
  5285.         curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
  5286.     }
  5287.     }
  5288. #endif
  5289.  
  5290. #ifdef FEAT_STL_OPT
  5291.     /* 'statusline' or 'rulerformat' */
  5292.     else if (varp == &p_stl || varp == &p_ruf)
  5293.     {
  5294.     int wid;
  5295.  
  5296.     if (varp == &p_ruf)    /* reset ru_wid first */
  5297.         ru_wid = 0;
  5298.     s = *varp;
  5299.     if (varp == &p_ruf && *s == '%')
  5300.     {
  5301.         /* set ru_wid if 'ruf' starts with "%99(" */
  5302.         if (*++s == '-')    /* ignore a '-' */
  5303.         s++;
  5304.         wid = getdigits(&s);
  5305.         if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
  5306.         ru_wid = wid;
  5307.         else
  5308.         errmsg = check_stl_option(p_ruf);
  5309.     }
  5310.     else
  5311.         errmsg = check_stl_option(s);
  5312.     if (varp == &(p_ruf) && errmsg == NULL)
  5313.         comp_col();
  5314.     }
  5315. #endif
  5316.  
  5317. #ifdef FEAT_INS_EXPAND
  5318.     /* check if it is a valid value for 'complete' -- Acevedo */
  5319.     else if (gvarp == &p_cpt)
  5320.     {
  5321.     for (s = *varp; *s;)
  5322.     {
  5323.         while(*s == ',' || *s == ' ')
  5324.         s++;
  5325.         if (!*s)
  5326.         break;
  5327.         if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
  5328.         {
  5329.         errmsg = illegal_char(errbuf, *s);
  5330.         break;
  5331.         }
  5332.         if (*++s != NUL && *s != ',' && *s != ' ')
  5333.         {
  5334.         if (s[-1] == 'k' || s[-1] == 's')
  5335.         {
  5336.             /* skip optional filename after 'k' and 's' */
  5337.             while (*s && *s != ',' && *s != ' ')
  5338.             {
  5339.             if (*s == '\\')
  5340.                 ++s;
  5341.             ++s;
  5342.             }
  5343.         }
  5344.         else
  5345.         {
  5346.             if (errbuf != NULL)
  5347.             {
  5348.             sprintf((char *)errbuf,
  5349.                      _("E535: Illegal character after <%c>"),
  5350.                      *--s);
  5351.             errmsg = errbuf;
  5352.             }
  5353.             else
  5354.             errmsg = (char_u *)"";
  5355.             break;
  5356.         }
  5357.         }
  5358.     }
  5359.     }
  5360. #endif /* FEAT_INS_EXPAND */
  5361.  
  5362.  
  5363. #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
  5364.     else if (varp == &p_toolbar)
  5365.     {
  5366.     if (opt_strings_flags(p_toolbar, p_toolbar_values,
  5367.                   &toolbar_flags, TRUE) != OK)
  5368.         errmsg = e_invarg;
  5369.     else
  5370.         gui_mch_show_toolbar((toolbar_flags &
  5371.                   (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
  5372.     }
  5373. #endif
  5374.  
  5375. #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
  5376.     /* 'toolbariconsize': GTK+ 2 only */
  5377.     else if (varp == &p_tbis)
  5378.     {
  5379.     if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
  5380.         errmsg = e_invarg;
  5381.     else
  5382.         gui_mch_show_toolbar((toolbar_flags &
  5383.                   (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
  5384.     }
  5385. #endif
  5386.  
  5387.     /* 'pastetoggle': translate key codes like in a mapping */
  5388.     else if (varp == &p_pt)
  5389.     {
  5390.     if (*p_pt)
  5391.     {
  5392.         (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
  5393.         if (p != NULL)
  5394.         {
  5395.         if (new_value_alloced)
  5396.             free_string_option(p_pt);
  5397.         p_pt = p;
  5398.         new_value_alloced = TRUE;
  5399.         }
  5400.     }
  5401.     }
  5402.  
  5403.     /* 'backspace' */
  5404.     else if (varp == &p_bs)
  5405.     {
  5406.     if (isdigit(*p_bs))
  5407.     {
  5408.         if (*p_bs >'2' || p_bs[1] != NUL)
  5409.         errmsg = e_invarg;
  5410.     }
  5411.     else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
  5412.         errmsg = e_invarg;
  5413.     }
  5414.  
  5415.     /* 'casemap' */
  5416.     else if (varp == &p_cmp)
  5417.     {
  5418.     if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
  5419.         errmsg = e_invarg;
  5420.     }
  5421.  
  5422. #ifdef FEAT_DIFF
  5423.     /* 'diffopt' */
  5424.     else if (varp == &p_dip)
  5425.     {
  5426.     if (diffopt_changed() == FAIL)
  5427.         errmsg = e_invarg;
  5428.     }
  5429. #endif
  5430.  
  5431. #ifdef FEAT_FOLDING
  5432.     /* 'foldmethod' */
  5433.     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
  5434.     {
  5435.     if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
  5436.         || *curwin->w_p_fdm == NUL)
  5437.         errmsg = e_invarg;
  5438.     else
  5439.         foldUpdateAll(curwin);
  5440.     }
  5441. # ifdef FEAT_EVAL
  5442.     /* 'foldexpr' */
  5443.     else if (varp == &curwin->w_p_fde)
  5444.     {
  5445.     if (foldmethodIsExpr(curwin))
  5446.         foldUpdateAll(curwin);
  5447.     }
  5448. # endif
  5449.     /* 'foldmarker' */
  5450.     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
  5451.     {
  5452.     p = vim_strchr(*varp, ',');
  5453.     if (p == NULL)
  5454.         errmsg = (char_u *)N_("E536: comma required");
  5455.     else if (p == *varp || p[1] == NUL)
  5456.         errmsg = e_invarg;
  5457.     else if (foldmethodIsMarker(curwin))
  5458.         foldUpdateAll(curwin);
  5459.     }
  5460.     /* 'commentstring' */
  5461.     else if (gvarp == &p_cms)
  5462.     {
  5463.     if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
  5464.         errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
  5465.     }
  5466.     /* 'foldopen' */
  5467.     else if (varp == &p_fdo)
  5468.     {
  5469.     if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
  5470.         errmsg = e_invarg;
  5471.     }
  5472.     /* 'foldclose' */
  5473.     else if (varp == &p_fcl)
  5474.     {
  5475.     if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
  5476.         errmsg = e_invarg;
  5477.     }
  5478. #endif
  5479.  
  5480. #ifdef FEAT_VIRTUALEDIT
  5481.     /* 'virtualedit' */
  5482.     else if (varp == &p_ve)
  5483.     {
  5484.     if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
  5485.         errmsg = e_invarg;
  5486.     else if (STRCMP(p_ve, oldval) != 0)
  5487.         /* Recompute cursor position in case the new ve setting
  5488.          * changes something. */
  5489.         coladvance(curwin->w_virtcol);
  5490.     }
  5491. #endif
  5492.  
  5493. #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
  5494.     else if (varp == &p_csqf)
  5495.     {
  5496.     if (p_csqf != NULL)
  5497.     {
  5498.         char_u *p = p_csqf;
  5499.  
  5500.         while (*p != NUL)
  5501.         {
  5502.         if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
  5503.             || p[1] == NUL
  5504.             || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
  5505.             || (p[2] != NUL && p[2] != ','))
  5506.         {
  5507.             errmsg = e_invarg;
  5508.             break;
  5509.         }
  5510.         else if (p[2] == NUL)
  5511.             break;
  5512.         else
  5513.             p += 3;
  5514.         }
  5515.     }
  5516.     }
  5517. #endif
  5518.  
  5519.     /* Options that are a list of flags. */
  5520.     else
  5521.     {
  5522.     p = NULL;
  5523.     if (varp == &p_ww)
  5524.         p = (char_u *)WW_ALL;
  5525.     if (varp == &p_shm)
  5526.         p = (char_u *)SHM_ALL;
  5527.     else if (varp == &(p_cpo))
  5528.         p = (char_u *)CPO_ALL;
  5529.     else if (varp == &(curbuf->b_p_fo))
  5530.         p = (char_u *)FO_ALL;
  5531.     else if (varp == &p_mouse)
  5532.     {
  5533. #ifdef FEAT_MOUSE
  5534.         p = (char_u *)MOUSE_ALL;
  5535. #else
  5536.         if (*p_mouse != NUL)
  5537.         errmsg = (char_u *)N_("E538: No mouse support");
  5538. #endif
  5539.     }
  5540. #if defined(FEAT_GUI)
  5541.     else if (varp == &p_go)
  5542.         p = (char_u *)GO_ALL;
  5543. #endif
  5544.     if (p != NULL)
  5545.     {
  5546.         for (s = *varp; *s; ++s)
  5547.         if (vim_strchr(p, *s) == NULL)
  5548.         {
  5549.             errmsg = illegal_char(errbuf, *s);
  5550.             break;
  5551.         }
  5552.     }
  5553.     }
  5554.  
  5555.     /*
  5556.      * If error detected, restore the previous value.
  5557.      */
  5558.     if (errmsg != NULL)
  5559.     {
  5560.     if (new_value_alloced)
  5561.         free_string_option(*varp);
  5562.     *varp = oldval;
  5563.     /*
  5564.      * When resetting some values, need to act on it.
  5565.      */
  5566.     if (did_chartab)
  5567.         (void)init_chartab();
  5568.     if (varp == &p_hl)
  5569.         (void)highlight_changed();
  5570.     }
  5571.     else
  5572.     {
  5573. #ifdef FEAT_EVAL
  5574.     /* Remember where the option was set. */
  5575.     options[opt_idx].scriptID = current_SID;
  5576. #endif
  5577.     /*
  5578.      * Free string options that are in allocated memory.
  5579.      */
  5580.     if (options[opt_idx].flags & P_ALLOCED)
  5581.         free_string_option(oldval);
  5582.     if (new_value_alloced)
  5583.         options[opt_idx].flags |= P_ALLOCED;
  5584.     else
  5585.         options[opt_idx].flags &= ~P_ALLOCED;
  5586.  
  5587.     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
  5588.         && (int)options[opt_idx].indir >= PV_BOTH)
  5589.     {
  5590.         /* global option with local value set to use global value; free
  5591.          * the local value and make it empty */
  5592.         p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
  5593.         free_string_option(*(char_u **)p);
  5594.         *(char_u **)p = empty_option;
  5595.     }
  5596.  
  5597.     /* May set global value for local option. */
  5598.     else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
  5599.         set_string_option_global(opt_idx, varp);
  5600.     }
  5601.  
  5602. #ifdef FEAT_MOUSE
  5603.     if (varp == &p_mouse)
  5604.     {
  5605. # ifdef FEAT_MOUSE_TTY
  5606.     if (*p_mouse == NUL)
  5607.         mch_setmouse(FALSE);    /* switch mouse off */
  5608.     else
  5609. # endif
  5610.         setmouse();            /* in case 'mouse' changed */
  5611.     }
  5612. #endif
  5613.  
  5614.     if (curwin->w_curswant != MAXCOL)
  5615.     curwin->w_set_curswant = TRUE;  /* in case 'showbreak' changed */
  5616.     check_redraw(options[opt_idx].flags);
  5617.  
  5618.     return errmsg;
  5619. }
  5620.  
  5621. /*
  5622.  * Handle setting 'listchars' or 'fillchars'.
  5623.  * Returns error message, NULL if it's OK.
  5624.  */
  5625.     static char_u *
  5626. set_chars_option(varp)
  5627.     char_u    **varp;
  5628. {
  5629.     int        round, i, len, entries;
  5630.     char_u    *p, *s;
  5631.     int        c1, c2 = 0;
  5632.     struct charstab
  5633.     {
  5634.     int    *cp;
  5635.     char    *name;
  5636.     };
  5637. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5638.     static struct charstab filltab[] =
  5639.     {
  5640.     {&fill_stl,    "stl"},
  5641.     {&fill_stlnc,    "stlnc"},
  5642.     {&fill_vert,    "vert"},
  5643.     {&fill_fold,    "fold"},
  5644.     {&fill_diff,    "diff"},
  5645.     };
  5646. #endif
  5647.     static struct charstab lcstab[] =
  5648.     {
  5649.     {&lcs_eol,    "eol"},
  5650.     {&lcs_ext,    "extends"},
  5651.     {&lcs_prec,    "precedes"},
  5652.     {&lcs_tab2,    "tab"},
  5653.     {&lcs_trail,    "trail"},
  5654.     };
  5655.     struct charstab *tab;
  5656.  
  5657. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5658.     if (varp == &p_lcs)
  5659. #endif
  5660.     {
  5661.     tab = lcstab;
  5662.     entries = sizeof(lcstab) / sizeof(struct charstab);
  5663.     }
  5664. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5665.     else
  5666.     {
  5667.     tab = filltab;
  5668.     entries = sizeof(filltab) / sizeof(struct charstab);
  5669.     }
  5670. #endif
  5671.  
  5672.     /* first round: check for valid value, second round: assign values */
  5673.     for (round = 0; round <= 1; ++round)
  5674.     {
  5675.     if (round)
  5676.     {
  5677.         /* After checking that the value is valid: set defaults: space for
  5678.          * 'fillchars', NUL for 'listchars' */
  5679.         for (i = 0; i < entries; ++i)
  5680.         *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
  5681.         if (varp == &p_lcs)
  5682.         lcs_tab1 = NUL;
  5683. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5684.         else
  5685.         fill_diff = '-';
  5686. #endif
  5687.     }
  5688.     p = *varp;
  5689.     while (*p)
  5690.     {
  5691.         for (i = 0; i < entries; ++i)
  5692.         {
  5693.         len = (int)STRLEN(tab[i].name);
  5694.         if (STRNCMP(p, tab[i].name, len) == 0
  5695.             && p[len] == ':'
  5696.             && p[len + 1] != NUL)
  5697.         {
  5698.             s = p + len + 1;
  5699. #ifdef FEAT_MBYTE
  5700.             c1 = mb_ptr2char_adv(&s);
  5701. #else
  5702.             c1 = *s++;
  5703. #endif
  5704.             if (tab[i].cp == &lcs_tab2)
  5705.             {
  5706.             if (*s == NUL)
  5707.                 continue;
  5708. #ifdef FEAT_MBYTE
  5709.             c2 = mb_ptr2char_adv(&s);
  5710. #else
  5711.             c2 = *s++;
  5712. #endif
  5713.             }
  5714.             if (*s == ',' || *s == NUL)
  5715.             {
  5716.             if (round)
  5717.             {
  5718.                 if (tab[i].cp == &lcs_tab2)
  5719.                 {
  5720.                 lcs_tab1 = c1;
  5721.                 lcs_tab2 = c2;
  5722.                 }
  5723.                 else
  5724.                 *(tab[i].cp) = c1;
  5725.  
  5726.             }
  5727.             p = s;
  5728.             break;
  5729.             }
  5730.         }
  5731.         }
  5732.  
  5733.         if (i == entries)
  5734.         return e_invarg;
  5735.         if (*p == ',')
  5736.         ++p;
  5737.     }
  5738.     }
  5739.  
  5740.     return NULL;    /* no error */
  5741. }
  5742.  
  5743. #ifdef FEAT_STL_OPT
  5744. /*
  5745.  * Check validity of options with the 'statusline' format.
  5746.  * Return error message or NULL.
  5747.  */
  5748.     char_u *
  5749. check_stl_option(s)
  5750.     char_u    *s;
  5751. {
  5752.     int        itemcnt = 0;
  5753.     int        groupdepth = 0;
  5754.     static char_u   errbuf[80];
  5755.  
  5756.     while (*s && itemcnt < STL_MAX_ITEM)
  5757.     {
  5758.     /* Check for valid keys after % sequences */
  5759.     while (*s && *s != '%')
  5760.         s++;
  5761.     if (!*s)
  5762.         break;
  5763.     s++;
  5764.     if (*s != '%' && *s != ')')
  5765.         ++itemcnt;
  5766.     if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
  5767.     {
  5768.         s++;
  5769.         continue;
  5770.     }
  5771.     if (*s == ')')
  5772.     {
  5773.         s++;
  5774.         if (--groupdepth < 0)
  5775.         break;
  5776.         continue;
  5777.     }
  5778.     if (*s == '-')
  5779.         s++;
  5780.     while (isdigit(*s))
  5781.         s++;
  5782.     if (*s == STL_HIGHLIGHT)
  5783.         continue;
  5784.     if (*s == '.')
  5785.     {
  5786.         s++;
  5787.         while (*s && isdigit(*s))
  5788.         s++;
  5789.     }
  5790.     if (*s == '(')
  5791.     {
  5792.         groupdepth++;
  5793.         continue;
  5794.     }
  5795.     if (vim_strchr(STL_ALL, *s) == NULL)
  5796.     {
  5797.         return illegal_char(errbuf, *s);
  5798.     }
  5799.     if (*s == '{')
  5800.     {
  5801.         s++;
  5802.         while (*s != '}' && *s)
  5803.         s++;
  5804.         if (*s != '}')
  5805.         return (char_u *)N_("E540: Unclosed expression sequence");
  5806.     }
  5807.     }
  5808.     if (itemcnt >= STL_MAX_ITEM)
  5809.     return (char_u *)N_("E541: too many items");
  5810.     if (groupdepth != 0)
  5811.     return (char_u *)N_("E542: unbalanced groups");
  5812.     return NULL;
  5813. }
  5814. #endif
  5815.  
  5816. #ifdef FEAT_CLIPBOARD
  5817. /*
  5818.  * Extract the items in the 'clipboard' option and set global values.
  5819.  */
  5820.     static char_u *
  5821. check_clipboard_option()
  5822. {
  5823.     int        new_unnamed = FALSE;
  5824.     int        new_autoselect = FALSE;
  5825.     int        new_autoselectml = FALSE;
  5826.     regprog_T    *new_exclude_prog = NULL;
  5827.     char_u    *errmsg = NULL;
  5828.     char_u    *p;
  5829.  
  5830.     for (p = p_cb; *p != NUL; )
  5831.     {
  5832.     if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
  5833.     {
  5834.         new_unnamed = TRUE;
  5835.         p += 7;
  5836.     }
  5837.     else if (STRNCMP(p, "autoselect", 10) == 0
  5838.                     && (p[10] == ',' || p[10] == NUL))
  5839.     {
  5840.         new_autoselect = TRUE;
  5841.         p += 10;
  5842.     }
  5843.     else if (STRNCMP(p, "autoselectml", 12) == 0
  5844.                     && (p[12] == ',' || p[12] == NUL))
  5845.     {
  5846.         new_autoselectml = TRUE;
  5847.         p += 12;
  5848.     }
  5849.     else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
  5850.     {
  5851.         p += 8;
  5852.         new_exclude_prog = vim_regcomp(p, RE_MAGIC);
  5853.         if (new_exclude_prog == NULL)
  5854.         errmsg = e_invarg;
  5855.         break;
  5856.     }
  5857.     else
  5858.     {
  5859.         errmsg = e_invarg;
  5860.         break;
  5861.     }
  5862.     if (*p == ',')
  5863.         ++p;
  5864.     }
  5865.     if (errmsg == NULL)
  5866.     {
  5867.     clip_unnamed = new_unnamed;
  5868.     clip_autoselect = new_autoselect;
  5869.     clip_autoselectml = new_autoselectml;
  5870.     vim_free(clip_exclude_prog);
  5871.     clip_exclude_prog = new_exclude_prog;
  5872.     }
  5873.     else
  5874.     vim_free(new_exclude_prog);
  5875.  
  5876.     return errmsg;
  5877. }
  5878. #endif
  5879.  
  5880. /*
  5881.  * Set the value of a boolean option, and take care of side effects.
  5882.  * Returns NULL for success, or an error message for an error.
  5883.  */
  5884.     static char_u *
  5885. set_bool_option(opt_idx, varp, value, opt_flags)
  5886.     int        opt_idx;        /* index in options[] table */
  5887.     char_u    *varp;            /* pointer to the option variable */
  5888.     int        value;            /* new value */
  5889.     int        opt_flags;        /* OPT_LOCAL and/or OPT_GLOBAL */
  5890. {
  5891.     int        old_value = *(int *)varp;
  5892.  
  5893. #ifdef FEAT_GUI
  5894.     need_mouse_correct = TRUE;
  5895. #endif
  5896.  
  5897.     /* Disallow changing some options from secure mode */
  5898.     if ((secure
  5899. #ifdef HAVE_SANDBOX
  5900.         || sandbox != 0
  5901. #endif
  5902.         ) && (options[opt_idx].flags & P_SECURE))
  5903.     return e_secure;
  5904.  
  5905.     *(int *)varp = value;        /* set the new value */
  5906. #ifdef FEAT_EVAL
  5907.     /* Remember where the option was set. */
  5908.     options[opt_idx].scriptID = current_SID;
  5909. #endif
  5910.  
  5911.     /* May set global value for local option. */
  5912.     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
  5913.     *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
  5914.  
  5915.     /*
  5916.      * Handle side effects of changing a bool option.
  5917.      */
  5918.  
  5919.     /* 'compatible' */
  5920.     if ((int *)varp == &p_cp)
  5921.     {
  5922.     compatible_set();
  5923.     }
  5924.  
  5925.     /* when 'readonly' is reset globally, also reset readonlymode */
  5926.     else if ((int *)varp == &curbuf->b_p_ro)
  5927.     {
  5928.     if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
  5929.         readonlymode = FALSE;
  5930. #ifdef FEAT_TITLE
  5931.     need_maketitle = TRUE;
  5932. #endif
  5933.     }
  5934.  
  5935. #ifdef FEAT_TITLE
  5936.     /* when 'modifiable' is changed, redraw the window title */
  5937.     else if ((int *)varp == &curbuf->b_p_ma)
  5938.     need_maketitle = TRUE;
  5939.     /* when 'endofline' is changed, redraw the window title */
  5940.     else if ((int *)varp == &curbuf->b_p_eol)
  5941.     need_maketitle = TRUE;
  5942. #endif
  5943.  
  5944.     /* when 'bin' is set also set some other options */
  5945.     else if ((int *)varp == &curbuf->b_p_bin)
  5946.     {
  5947.     set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
  5948. #ifdef FEAT_TITLE
  5949.     need_maketitle = TRUE;
  5950. #endif
  5951.     }
  5952.  
  5953. #ifdef FEAT_AUTOCMD
  5954.     /* when 'buflisted' changes, trigger autocommands */
  5955.     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
  5956.     {
  5957.     apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
  5958.                             NULL, NULL, TRUE, curbuf);
  5959.     }
  5960. #endif
  5961.  
  5962.     /* when 'swf' is set, create swapfile, when reset remove swapfile */
  5963.     else if ((int *)varp == &curbuf->b_p_swf)
  5964.     {
  5965.     if (curbuf->b_p_swf && p_uc)
  5966.         ml_open_file(curbuf);        /* create the swap file */
  5967.     else
  5968.         mf_close_file(curbuf, TRUE);    /* remove the swap file */
  5969.     }
  5970.  
  5971.     /* when 'terse' is set change 'shortmess' */
  5972.     else if ((int *)varp == &p_terse)
  5973.     {
  5974.     char_u    *p;
  5975.  
  5976.     p = vim_strchr(p_shm, SHM_SEARCH);
  5977.  
  5978.     /* insert 's' in p_shm */
  5979.     if (p_terse && p == NULL)
  5980.     {
  5981.         STRCPY(IObuff, p_shm);
  5982.         STRCAT(IObuff, "s");
  5983.         set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
  5984.     }
  5985.     /* remove 's' from p_shm */
  5986.     else if (!p_terse && p != NULL)
  5987.         mch_memmove(p, p + 1, STRLEN(p));
  5988.     }
  5989.  
  5990.     /* when 'paste' is set or reset also change other options */
  5991.     else if ((int *)varp == &p_paste)
  5992.     {
  5993.     paste_option_changed();
  5994.     }
  5995.  
  5996.     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
  5997.     else if ((int *)varp == &p_ic && p_hls)
  5998.     {
  5999.     redraw_all_later(NOT_VALID);
  6000.     }
  6001.  
  6002. #ifdef FEAT_SEARCH_EXTRA
  6003.     /* when 'hlsearch' is set or reset: reset no_hlsearch */
  6004.     else if ((int *)varp == &p_hls)
  6005.     {
  6006.     no_hlsearch = FALSE;
  6007.     }
  6008. #endif
  6009.  
  6010. #ifdef FEAT_SCROLLBIND
  6011.     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
  6012.      * at the end of normal_cmd() */
  6013.     else if ((int *)varp == &curwin->w_p_scb)
  6014.     {
  6015.     if (curwin->w_p_scb)
  6016.         do_check_scrollbind(FALSE);
  6017.     }
  6018. #endif
  6019.  
  6020. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  6021.     /* There can be only one window with 'previewwindow' set. */
  6022.     else if ((int *)varp == &curwin->w_p_pvw)
  6023.     {
  6024.     if (curwin->w_p_pvw)
  6025.     {
  6026.         win_T    *win;
  6027.  
  6028.         for (win = firstwin; win != NULL; win = win->w_next)
  6029.         if (win->w_p_pvw && win != curwin)
  6030.         {
  6031.             curwin->w_p_pvw = FALSE;
  6032.             return (char_u *)N_("E590: A preview window already exists");
  6033.         }
  6034.     }
  6035.     }
  6036. #endif
  6037.  
  6038.     /* when 'textmode' is set or reset also change 'fileformat' */
  6039.     else if ((int *)varp == &curbuf->b_p_tx)
  6040.     {
  6041.     set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
  6042.     }
  6043.  
  6044.     /* when 'textauto' is set or reset also change 'fileformats' */
  6045.     else if ((int *)varp == &p_ta)
  6046.     {
  6047.     set_string_option_direct((char_u *)"ffs", -1,
  6048.                  p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
  6049.                             OPT_FREE | opt_flags);
  6050.     }
  6051.  
  6052.     /*
  6053.      * When 'lisp' option changes include/exclude '-' in
  6054.      * keyword characters.
  6055.      */
  6056. #ifdef FEAT_LISP
  6057.     else if (varp == (char_u *)&(curbuf->b_p_lisp))
  6058.     {
  6059.     (void)buf_init_chartab(curbuf, FALSE);        /* ignore errors */
  6060.     }
  6061. #endif
  6062.  
  6063. #ifdef FEAT_TITLE
  6064.     /* when 'title' changed, may need to change the title; same for 'icon' */
  6065.     else if ((int *)varp == &p_title)
  6066.     {
  6067.     did_set_title(FALSE);
  6068.     }
  6069.  
  6070.     else if ((int *)varp == &p_icon)
  6071.     {
  6072.     did_set_title(TRUE);
  6073.     }
  6074. #endif
  6075.  
  6076.     else if ((int *)varp == &curbuf->b_changed)
  6077.     {
  6078.     if (!value)
  6079.         save_file_ff(curbuf);    /* Buffer is unchanged */
  6080. #ifdef FEAT_TITLE
  6081.     need_maketitle = TRUE;
  6082. #endif
  6083. #ifdef FEAT_AUTOCMD
  6084.     modified_was_set = value;
  6085. #endif
  6086.     }
  6087.  
  6088. #ifdef BACKSLASH_IN_FILENAME
  6089.     else if ((int *)varp == &p_ssl)
  6090.     {
  6091.     if (p_ssl)
  6092.     {
  6093.         psepc = '/';
  6094.         psepcN = '\\';
  6095.         pseps[0] = '/';
  6096.         psepsN[0] = '\\';
  6097.     }
  6098.     else
  6099.     {
  6100.         psepc = '\\';
  6101.         psepcN = '/';
  6102.         pseps[0] = '\\';
  6103.         psepsN[0] = '/';
  6104.     }
  6105.  
  6106.     /* need to adjust the file name arguments and buffer names. */
  6107.     buflist_slash_adjust();
  6108.     alist_slash_adjust();
  6109. # ifdef FEAT_EVAL
  6110.     scriptnames_slash_adjust();
  6111. # endif
  6112.     }
  6113. #endif
  6114.  
  6115.     /* If 'wrap' is set, set w_leftcol to zero. */
  6116.     else if ((int *)varp == &curwin->w_p_wrap)
  6117.     {
  6118.     if (curwin->w_p_wrap)
  6119.         curwin->w_leftcol = 0;
  6120.     }
  6121.  
  6122. #ifdef FEAT_WINDOWS
  6123.     else if ((int *)varp == &p_ea)
  6124.     {
  6125.     if (p_ea && !old_value)
  6126.         win_equal(curwin, FALSE, 0);
  6127.     }
  6128. #endif
  6129.  
  6130.     else if ((int *)varp == &p_wiv)
  6131.     {
  6132.     /*
  6133.      * When 'weirdinvert' changed, set/reset 't_xs'.
  6134.      * Then set 'weirdinvert' according to value of 't_xs'.
  6135.      */
  6136.     if (p_wiv && !old_value)
  6137.         T_XS = (char_u *)"y";
  6138.     else if (!p_wiv && old_value)
  6139.         T_XS = empty_option;
  6140.     p_wiv = (*T_XS != NUL);
  6141.     }
  6142.  
  6143. #if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
  6144.     || defined(FEAT_NETBEANS_INTG))
  6145.     else if ((int *)varp == &p_beval)
  6146.     {
  6147.     extern BalloonEval    *balloonEval;
  6148.  
  6149.     if (p_beval == TRUE)
  6150.         gui_mch_enable_beval_area(balloonEval);
  6151.     else
  6152.         gui_mch_disable_beval_area(balloonEval);
  6153.     }
  6154.  
  6155.     else if ((int *)varp == &p_acd)
  6156.     {
  6157.     if (p_acd && curbuf->b_ffname != NULL
  6158.         && vim_chdirfile(curbuf->b_ffname) == OK)
  6159.         shorten_fnames(TRUE);
  6160.     }
  6161. #endif
  6162.  
  6163. #ifdef FEAT_DIFF
  6164.     /* 'diff' */
  6165.     else if ((int *)varp == &curwin->w_p_diff)
  6166.     {
  6167.     win_T    *wp;
  6168.  
  6169.     if (!curwin->w_p_diff)
  6170.     {
  6171.         /* When there is no window showing a diff for this buffer, remove
  6172.          * it from the diffs. */
  6173.         for (wp = firstwin; wp != NULL; wp = wp->w_next)
  6174.         if (wp->w_buffer == curwin->w_buffer && wp->w_p_diff)
  6175.             break;
  6176.         if (wp == NULL)
  6177.         diff_buf_delete(curwin->w_buffer);
  6178.     }
  6179.     else
  6180.         diff_buf_add(curwin->w_buffer);
  6181. #ifdef FEAT_FOLDING
  6182.     if (foldmethodIsDiff(curwin))
  6183.         foldUpdateAll(curwin);
  6184. #endif
  6185.     }
  6186. #endif
  6187.  
  6188. #ifdef USE_IM_CONTROL
  6189.     /* 'imdisable' */
  6190.     else if ((int *)varp == &p_imdisable)
  6191.     {
  6192.     /* Only de-activate it here, it will be enabled when changing mode. */
  6193.     if (p_imdisable)
  6194.         im_set_active(FALSE);
  6195.     }
  6196. #endif
  6197.  
  6198. #ifdef FEAT_FKMAP
  6199.     else if ((int *)varp == &p_altkeymap)
  6200.     {
  6201.     if (old_value != p_altkeymap)
  6202.     {
  6203.         if (!p_altkeymap)
  6204.         {
  6205.         p_hkmap = p_fkmap;
  6206.         p_fkmap = 0;
  6207.         }
  6208.         else
  6209.         {
  6210.         p_fkmap = p_hkmap;
  6211.         p_hkmap = 0;
  6212.         }
  6213.         (void)init_chartab();
  6214.     }
  6215.     }
  6216.  
  6217.     /*
  6218.      * In case some second language keymapping options have changed, check
  6219.      * and correct the setting in a consistent way.
  6220.      */
  6221.  
  6222.     /*
  6223.      * If hkmap or fkmap are set, reset Arabic keymapping.
  6224.      */
  6225.     if ((p_hkmap || p_fkmap) && p_altkeymap)
  6226.     {
  6227.     p_altkeymap = p_fkmap;
  6228. # ifdef FEAT_ARABIC
  6229.     curwin->w_p_arab = FALSE;
  6230. # endif
  6231.     (void)init_chartab();
  6232.     }
  6233.  
  6234.     /*
  6235.      * If hkmap set, reset Farsi keymapping.
  6236.      */
  6237.     if (p_hkmap && p_altkeymap)
  6238.     {
  6239.     p_altkeymap = 0;
  6240.     p_fkmap = 0;
  6241. # ifdef FEAT_ARABIC
  6242.     curwin->w_p_arab = FALSE;
  6243. # endif
  6244.     (void)init_chartab();
  6245.     }
  6246.  
  6247.     /*
  6248.      * If fkmap set, reset Hebrew keymapping.
  6249.      */
  6250.     if (p_fkmap && !p_altkeymap)
  6251.     {
  6252.     p_altkeymap = 1;
  6253.     p_hkmap = 0;
  6254. # ifdef FEAT_ARABIC
  6255.     curwin->w_p_arab = FALSE;
  6256. # endif
  6257.     (void)init_chartab();
  6258.     }
  6259. #endif
  6260.  
  6261. #ifdef FEAT_ARABIC
  6262.     if ((int *)varp == &curwin->w_p_arab)
  6263.     {
  6264.     if (curwin->w_p_arab)
  6265.     {
  6266.         /*
  6267.          * 'arabic' is set, handle various sub-settings.
  6268.          */
  6269.         if (!p_tbidi)
  6270.         {
  6271.         /* set rightleft mode */
  6272.         if (!curwin->w_p_rl)
  6273.         {
  6274.             curwin->w_p_rl = TRUE;
  6275.             changed_window_setting();
  6276.         }
  6277.  
  6278.         /* Enable Arabic shaping (major part of what Arabic requires) */
  6279.         if (!p_arshape)
  6280.         {
  6281.             p_arshape = TRUE;
  6282.             redraw_later_clear();
  6283.         }
  6284.         }
  6285.  
  6286.         /* Arabic requires a utf-8 encoding, inform the user if its not
  6287.          * set. */
  6288.         if (STRCMP(p_enc, "utf-8") != 0)
  6289.         MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
  6290.             hl_attr(HLF_W));
  6291.  
  6292. # ifdef FEAT_MBYTE
  6293.         /* set 'delcombine' */
  6294.         p_deco = TRUE;
  6295. # endif
  6296.  
  6297. # ifdef FEAT_KEYMAP
  6298.         /* Force-set the necessary keymap for arabic */
  6299.         set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
  6300.                                    OPT_LOCAL);
  6301. # endif
  6302. # ifdef FEAT_FKMAP
  6303.         p_altkeymap = 0;
  6304.         p_hkmap = 0;
  6305.         p_fkmap = 0;
  6306.         (void)init_chartab();
  6307. # endif
  6308.     }
  6309.     else
  6310.     {
  6311.         /*
  6312.          * 'arabic' is reset, handle various sub-settings.
  6313.          */
  6314.         if (!p_tbidi)
  6315.         {
  6316.         /* reset rightleft mode */
  6317.         if (curwin->w_p_rl)
  6318.         {
  6319.             curwin->w_p_rl = FALSE;
  6320.             changed_window_setting();
  6321.         }
  6322.  
  6323.         /* 'arabicshape' isn't reset, it is a global option and
  6324.          * another window may still need it "on". */
  6325.         }
  6326.  
  6327.         /* 'delcombine' isn't reset, it is a global option and another
  6328.          * window may still want it "on". */
  6329.  
  6330. # ifdef FEAT_KEYMAP
  6331.         /* Revert to the default keymap */
  6332.         curbuf->b_p_iminsert = B_IMODE_NONE;
  6333.         curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
  6334. # endif
  6335.     }
  6336.     }
  6337. #endif
  6338.  
  6339.     /*
  6340.      * End of handling side effects for bool options.
  6341.      */
  6342.  
  6343.     options[opt_idx].flags |= P_WAS_SET;
  6344.  
  6345.     comp_col();                /* in case 'ruler' or 'showcmd' changed */
  6346.     if (curwin->w_curswant != MAXCOL)
  6347.     curwin->w_set_curswant = TRUE;  /* in case 'list' changed */
  6348.     check_redraw(options[opt_idx].flags);
  6349.  
  6350.     return NULL;
  6351. }
  6352.  
  6353. /*
  6354.  * Set the value of a number option, and take care of side effects.
  6355.  * Returns NULL for success, or an error message for an error.
  6356.  */
  6357.     static char_u *
  6358. set_num_option(opt_idx, varp, value, errbuf, opt_flags)
  6359.     int        opt_idx;        /* index in options[] table */
  6360.     char_u    *varp;            /* pointer to the option variable */
  6361.     long    value;            /* new value */
  6362.     char_u    *errbuf;        /* buffer for error messages */
  6363.     int        opt_flags;        /* OPT_LOCAL, OPT_GLOBAL and
  6364.                        OPT_MODELINE */
  6365. {
  6366.     char_u    *errmsg = NULL;
  6367.     long    old_value = *(long *)varp;
  6368.     long    old_Rows = Rows;    /* remember old Rows */
  6369.     long    old_Columns = Columns;    /* remember old Columns */
  6370.     long    *pp = (long *)varp;
  6371.  
  6372. #ifdef FEAT_GUI
  6373.     need_mouse_correct = TRUE;
  6374. #endif
  6375.  
  6376.     *pp = value;
  6377. #ifdef FEAT_EVAL
  6378.     /* Remember where the option was set. */
  6379.     options[opt_idx].scriptID = current_SID;
  6380. #endif
  6381.  
  6382.     if (curbuf->b_p_sw <= 0)
  6383.     {
  6384.     errmsg = e_positive;
  6385.     curbuf->b_p_sw = curbuf->b_p_ts;
  6386.     }
  6387.  
  6388.     /*
  6389.      * Number options that need some action when changed
  6390.      */
  6391. #ifdef FEAT_WINDOWS
  6392.     if (pp == &p_wh || pp == &p_hh)
  6393.     {
  6394.     if (p_wh < 1)
  6395.     {
  6396.         errmsg = e_positive;
  6397.         p_wh = 1;
  6398.     }
  6399.     if (p_wmh > p_wh)
  6400.     {
  6401.         errmsg = e_winheight;
  6402.         p_wh = p_wmh;
  6403.     }
  6404.     if (p_hh < 0)
  6405.     {
  6406.         errmsg = e_positive;
  6407.         p_hh = 0;
  6408.     }
  6409.  
  6410.     /* Change window height NOW */
  6411.     if (lastwin != firstwin)
  6412.     {
  6413.         if (pp == &p_wh && curwin->w_height < p_wh)
  6414.         win_setheight((int)p_wh);
  6415.         if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
  6416.         win_setheight((int)p_hh);
  6417.     }
  6418.     }
  6419.  
  6420.     /* 'winminheight' */
  6421.     else if (pp == &p_wmh)
  6422.     {
  6423.     if (p_wmh < 0)
  6424.     {
  6425.         errmsg = e_positive;
  6426.         p_wmh = 0;
  6427.     }
  6428.     if (p_wmh > p_wh)
  6429.     {
  6430.         errmsg = e_winheight;
  6431.         p_wmh = p_wh;
  6432.     }
  6433.     win_setminheight();
  6434.     }
  6435.  
  6436. # ifdef FEAT_VERTSPLIT
  6437.     if (pp == &p_wiw)
  6438.     {
  6439.     if (p_wiw < 1)
  6440.     {
  6441.         errmsg = e_positive;
  6442.         p_wiw = 1;
  6443.     }
  6444.     if (p_wmw > p_wiw)
  6445.     {
  6446.         errmsg = e_winwidth;
  6447.         p_wiw = p_wmw;
  6448.     }
  6449.  
  6450.     /* Change window width NOW */
  6451.     if (lastwin != firstwin && curwin->w_width < p_wiw)
  6452.         win_setwidth((int)p_wiw);
  6453.     }
  6454.  
  6455.     /* 'winminwidth' */
  6456.     else if (pp == &p_wmw)
  6457.     {
  6458.     if (p_wmw < 0)
  6459.     {
  6460.         errmsg = e_positive;
  6461.         p_wmw = 0;
  6462.     }
  6463.     if (p_wmw > p_wiw)
  6464.     {
  6465.         errmsg = e_winwidth;
  6466.         p_wmw = p_wiw;
  6467.     }
  6468.     win_setminheight();
  6469.     }
  6470. # endif
  6471.  
  6472. #endif
  6473.  
  6474. #ifdef FEAT_WINDOWS
  6475.     /* (re)set last window status line */
  6476.     else if (pp == &p_ls)
  6477.     {
  6478.     last_status(FALSE);
  6479.     }
  6480. #endif
  6481.  
  6482. #ifdef FEAT_GUI
  6483.     else if (pp == &p_linespace)
  6484.     {
  6485.     if (gui.in_use && gui_mch_adjust_charsize() == OK)
  6486.         gui_set_shellsize(FALSE, FALSE);
  6487.     }
  6488. #endif
  6489.  
  6490. #ifdef FEAT_FOLDING
  6491.     /* 'foldlevel' */
  6492.     else if (pp == &curwin->w_p_fdl)
  6493.     {
  6494.     if (curwin->w_p_fdl < 0)
  6495.         curwin->w_p_fdl = 0;
  6496.     newFoldLevel();
  6497.     }
  6498.  
  6499.     /* 'foldminlevel' */
  6500.     else if (pp == &curwin->w_p_fml)
  6501.     {
  6502.     foldUpdateAll(curwin);
  6503.     }
  6504.  
  6505.     /* 'foldnestmax' */
  6506.     else if (pp == &curwin->w_p_fdn)
  6507.     {
  6508.     if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
  6509.         foldUpdateAll(curwin);
  6510.     }
  6511.  
  6512.     /* 'foldcolumn' */
  6513.     else if (pp == &curwin->w_p_fdc)
  6514.     {
  6515.     if (curwin->w_p_fdc < 0)
  6516.     {
  6517.         errmsg = e_positive;
  6518.         curwin->w_p_fdc = 0;
  6519.     }
  6520.     else if (curwin->w_p_fdc > 12)
  6521.     {
  6522.         errmsg = e_invarg;
  6523.         curwin->w_p_fdc = 12;
  6524.     }
  6525.     }
  6526.  
  6527.     /* 'shiftwidth' or 'tabstop' */
  6528.     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
  6529.     {
  6530.     if (foldmethodIsIndent(curwin))
  6531.         foldUpdateAll(curwin);
  6532.     }
  6533. #endif /* FEAT_FOLDING */
  6534.  
  6535.     else if (pp == &curbuf->b_p_iminsert)
  6536.     {
  6537.     if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
  6538.     {
  6539.         errmsg = e_invarg;
  6540.         curbuf->b_p_iminsert = B_IMODE_NONE;
  6541.     }
  6542.     p_iminsert = curbuf->b_p_iminsert;
  6543.     if (termcap_active)    /* don't do this in the alternate screen */
  6544.         showmode();
  6545. #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
  6546.     /* Show/unshow value of 'keymap' in status lines. */
  6547.     status_redraw_curbuf();
  6548. #endif
  6549.     }
  6550.  
  6551.     else if (pp == &curbuf->b_p_imsearch)
  6552.     {
  6553.     if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
  6554.     {
  6555.         errmsg = e_invarg;
  6556.         curbuf->b_p_imsearch = B_IMODE_NONE;
  6557.     }
  6558.     p_imsearch = curbuf->b_p_imsearch;
  6559.     }
  6560.  
  6561. #ifdef FEAT_TITLE
  6562.     /* if 'titlelen' has changed, redraw the title */
  6563.     else if (pp == &p_titlelen)
  6564.     {
  6565.     if (p_titlelen < 0)
  6566.     {
  6567.         errmsg = e_positive;
  6568.         p_titlelen = 85;
  6569.     }
  6570.     if (starting != NO_SCREEN && old_value != p_titlelen)
  6571.         need_maketitle = TRUE;
  6572.     }
  6573. #endif
  6574.  
  6575.     /* if p_ch changed value, change the command line height */
  6576.     else if (pp == &p_ch)
  6577.     {
  6578.     if (p_ch < 1)
  6579.     {
  6580.         errmsg = e_positive;
  6581.         p_ch = 1;
  6582.     }
  6583.     if (p_ch != old_value)
  6584.         command_height(old_value);
  6585.     }
  6586.  
  6587.     /* when 'updatecount' changes from zero to non-zero, open swap files */
  6588.     else if (pp == &p_uc)
  6589.     {
  6590.     if (p_uc < 0)
  6591.     {
  6592.         errmsg = e_positive;
  6593.         p_uc = 100;
  6594.     }
  6595.     if (p_uc && !old_value)
  6596.         ml_open_files();
  6597.     }
  6598.  
  6599.     /*
  6600.      * Check the bounds for numeric options here
  6601.      */
  6602.     if (Rows < min_rows() && full_screen)
  6603.     {
  6604.     if (errbuf != NULL)
  6605.     {
  6606.         sprintf((char *)errbuf, _("E593: Need at least %d lines"), min_rows());
  6607.         errmsg = errbuf;
  6608.     }
  6609.     Rows = min_rows();
  6610.     }
  6611.     if (Columns < MIN_COLUMNS && full_screen)
  6612.     {
  6613.     if (errbuf != NULL)
  6614.     {
  6615.         sprintf((char *)errbuf, _("E594: Need at least %d columns"), MIN_COLUMNS);
  6616.         errmsg = errbuf;
  6617.     }
  6618.     Columns = MIN_COLUMNS;
  6619.     }
  6620.  
  6621. #ifdef DJGPP
  6622.     /* avoid a crash by checking for a too large value of 'columns' */
  6623.     if (old_Columns != Columns && full_screen && term_console)
  6624.     mch_check_columns();
  6625. #endif
  6626.  
  6627.     /*
  6628.      * If the screen (shell) height has been changed, assume it is the
  6629.      * physical screenheight.
  6630.      */
  6631.     if (old_Rows != Rows || old_Columns != Columns)
  6632.     {
  6633.     /* Changing the screen size is not allowed while updating the screen. */
  6634.     if (updating_screen)
  6635.         *pp = old_value;
  6636.     else if (full_screen
  6637. #ifdef FEAT_GUI
  6638.         && !gui.starting
  6639. #endif
  6640.         )
  6641.         set_shellsize((int)Columns, (int)Rows, TRUE);
  6642.     else
  6643.     {
  6644.         /* Postpone the resizing; check the size and cmdline position for
  6645.          * messages. */
  6646.         check_shellsize();
  6647.         if (cmdline_row > Rows - p_ch)
  6648.         cmdline_row = Rows - p_ch;
  6649.     }
  6650.     }
  6651.  
  6652.     if (curbuf->b_p_sts < 0)
  6653.     {
  6654.     errmsg = e_positive;
  6655.     curbuf->b_p_sts = 0;
  6656.     }
  6657.     if (curbuf->b_p_ts <= 0)
  6658.     {
  6659.     errmsg = e_positive;
  6660.     curbuf->b_p_ts = 8;
  6661.     }
  6662.     if (curbuf->b_p_tw < 0)
  6663.     {
  6664.     errmsg = e_positive;
  6665.     curbuf->b_p_tw = 0;
  6666.     }
  6667.     if (p_tm < 0)
  6668.     {
  6669.     errmsg = e_positive;
  6670.     p_tm = 0;
  6671.     }
  6672.     if ((curwin->w_p_scr <= 0
  6673.         || (curwin->w_p_scr > curwin->w_height
  6674.             && curwin->w_height > 0))
  6675.         && full_screen)
  6676.     {
  6677.     if (pp == &(curwin->w_p_scr))
  6678.     {
  6679.         if (curwin->w_p_scr != 0)
  6680.         errmsg = e_scroll;
  6681.         win_comp_scroll(curwin);
  6682.     }
  6683.     /* If 'scroll' became invalid because of a side effect silently adjust
  6684.      * it. */
  6685.     else if (curwin->w_p_scr <= 0)
  6686.         curwin->w_p_scr = 1;
  6687.     else /* curwin->w_p_scr > curwin->w_height */
  6688.         curwin->w_p_scr = curwin->w_height;
  6689.     }
  6690.     if (p_report < 0)
  6691.     {
  6692.     errmsg = e_positive;
  6693.     p_report = 1;
  6694.     }
  6695.     if ((p_sj < 0 || p_sj >= Rows) && full_screen)
  6696.     {
  6697.     if (Rows != old_Rows)    /* Rows changed, just adjust p_sj */
  6698.         p_sj = Rows / 2;
  6699.     else
  6700.     {
  6701.         errmsg = e_scroll;
  6702.         p_sj = 1;
  6703.     }
  6704.     }
  6705.     if (p_so < 0 && full_screen)
  6706.     {
  6707.     errmsg = e_scroll;
  6708.     p_so = 0;
  6709.     }
  6710.     if (p_siso < 0 && full_screen)
  6711.     {
  6712.     errmsg = e_positive;
  6713.     p_siso = 0;
  6714.     }
  6715. #ifdef FEAT_CMDWIN
  6716.     if (p_cwh < 1)
  6717.     {
  6718.     errmsg = e_positive;
  6719.     p_cwh = 1;
  6720.     }
  6721. #endif
  6722.     if (p_ut < 0)
  6723.     {
  6724.     errmsg = e_positive;
  6725.     p_ut = 2000;
  6726.     }
  6727.     if (p_ss < 0)
  6728.     {
  6729.     errmsg = e_positive;
  6730.     p_ss = 0;
  6731.     }
  6732.  
  6733.     /* May set global value for local option. */
  6734.     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
  6735.     *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
  6736.  
  6737.     options[opt_idx].flags |= P_WAS_SET;
  6738.  
  6739.     comp_col();                /* in case 'columns' or 'ls' changed */
  6740.     if (curwin->w_curswant != MAXCOL)
  6741.     curwin->w_set_curswant = TRUE;  /* in case 'tabstop' changed */
  6742.     check_redraw(options[opt_idx].flags);
  6743.  
  6744.     return errmsg;
  6745. }
  6746.  
  6747. /*
  6748.  * Called after an option changed: check if something needs to be redrawn.
  6749.  */
  6750.     static void
  6751. check_redraw(flags)
  6752.     long_u    flags;
  6753. {
  6754.     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
  6755.     int        clear = (flags & P_RCLR) == P_RCLR;
  6756.     int        all = ((flags & P_RALL) == P_RALL || clear);
  6757.  
  6758. #ifdef FEAT_WINDOWS
  6759.     if ((flags & P_RSTAT) || all)    /* mark all status lines dirty */
  6760.     status_redraw_all();
  6761. #endif
  6762.  
  6763.     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
  6764.     changed_window_setting();
  6765.     if (flags & P_RBUF)
  6766.     redraw_curbuf_later(NOT_VALID);
  6767.     if (clear)
  6768.     redraw_all_later(CLEAR);
  6769.     else if (all)
  6770.     redraw_all_later(NOT_VALID);
  6771. }
  6772.  
  6773. /*
  6774.  * Find index for option 'arg'.
  6775.  * Return -1 if not found.
  6776.  */
  6777.     static int
  6778. findoption(arg)
  6779.     char_u *arg;
  6780. {
  6781.     int            opt_idx;
  6782.     char        *s, *p;
  6783.     static short    quick_tab[27] = {0, 0};    /* quick access table */
  6784.     int            is_term_opt;
  6785.  
  6786.     /*
  6787.      * For first call: Initialize the quick-access table.
  6788.      * It contains the index for the first option that starts with a certain
  6789.      * letter.  There are 26 letters, plus the first "t_" option.
  6790.      */
  6791.     if (quick_tab[1] == 0)
  6792.     {
  6793.     p = options[0].fullname;
  6794.     for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
  6795.     {
  6796.         if (s[0] != p[0])
  6797.         {
  6798.         if (s[0] == 't' && s[1] == '_')
  6799.             quick_tab[26] = opt_idx;
  6800.         else
  6801.             quick_tab[CharOrdLow(s[0])] = opt_idx;
  6802.         }
  6803.         p = s;
  6804.     }
  6805.     }
  6806.  
  6807.     /*
  6808.      * Check for name starting with an illegal character.
  6809.      */
  6810. #ifdef EBCDIC
  6811.     if (!islower(arg[0]))
  6812. #else
  6813.     if (arg[0] < 'a' || arg[0] > 'z')
  6814. #endif
  6815.     return -1;
  6816.  
  6817.     is_term_opt = (arg[0] == 't' && arg[1] == '_');
  6818.     if (is_term_opt)
  6819.     opt_idx = quick_tab[26];
  6820.     else
  6821.     opt_idx = quick_tab[CharOrdLow(arg[0])];
  6822.     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
  6823.     {
  6824.     if (STRCMP(arg, s) == 0)            /* match full name */
  6825.         break;
  6826.     }
  6827.     if (s == NULL && !is_term_opt)
  6828.     {
  6829.     opt_idx = quick_tab[CharOrdLow(arg[0])];
  6830.     for ( ; options[opt_idx].fullname != NULL; opt_idx++)
  6831.     {
  6832.         s = options[opt_idx].shortname;
  6833.         if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
  6834.         break;
  6835.         s = NULL;
  6836.     }
  6837.     }
  6838.     if (s == NULL)
  6839.     opt_idx = -1;
  6840.     return opt_idx;
  6841. }
  6842.  
  6843. #if defined(FEAT_EVAL) || defined(FEAT_TCL)
  6844. /*
  6845.  * Get the value for an option.
  6846.  *
  6847.  * Returns:
  6848.  * Number or Toggle option: 1, *numval gets value.
  6849.  *         String option: 0, *stringval gets allocated string.
  6850.  * Hidden Number or Toggle option: -1.
  6851.  *         hidden String option: -2.
  6852.  *           unknown option: -3.
  6853.  */
  6854.     int
  6855. get_option_value(name, numval, stringval, opt_flags)
  6856.     char_u    *name;
  6857.     long    *numval;
  6858.     char_u    **stringval;        /* NULL when only checking existance */
  6859.     int        opt_flags;
  6860. {
  6861.     int        opt_idx;
  6862.     char_u    *varp;
  6863.  
  6864.     opt_idx = findoption(name);
  6865.     if (opt_idx < 0)            /* unknown option */
  6866.     return -3;
  6867.  
  6868.     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
  6869.  
  6870.     if (options[opt_idx].flags & P_STRING)
  6871.     {
  6872.     if (varp == NULL)            /* hidden option */
  6873.         return -2;
  6874.     if (stringval != NULL)
  6875.     {
  6876. #ifdef FEAT_CRYPT
  6877.         /* never return the value of the crypt key */
  6878.         if ((char_u **)varp == &curbuf->b_p_key)
  6879.         *stringval = vim_strsave((char_u *)"*****");
  6880.         else
  6881. #endif
  6882.         *stringval = vim_strsave(*(char_u **)(varp));
  6883.     }
  6884.     return 0;
  6885.     }
  6886.  
  6887.     if (varp == NULL)            /* hidden option */
  6888.     return -1;
  6889.     if (options[opt_idx].flags & P_NUM)
  6890.     *numval = *(long *)varp;
  6891.     else
  6892.     {
  6893.     /* Special case: 'modified' is b_changed, but we also want to consider
  6894.      * it set when 'ff' or 'fenc' changed. */
  6895.     if ((int *)varp == &curbuf->b_changed)
  6896.         *numval = curbufIsChanged();
  6897.     else
  6898.         *numval = *(int *)varp;
  6899.     }
  6900.     return 1;
  6901. }
  6902. #endif
  6903.  
  6904. /*
  6905.  * Set the value of option "name".
  6906.  * Use "string" for string options, use "number" for other options.
  6907.  */
  6908.     void
  6909. set_option_value(name, number, string, opt_flags)
  6910.     char_u    *name;
  6911.     long    number;
  6912.     char_u    *string;
  6913.     int        opt_flags;    /* OPT_LOCAL or 0 (both) */
  6914. {
  6915.     int        opt_idx;
  6916.     char_u    *varp;
  6917.  
  6918.     opt_idx = findoption(name);
  6919.     if (opt_idx == -1)
  6920.     EMSG2(_("E355: Unknown option: %s"), name);
  6921.     else if (options[opt_idx].flags & P_STRING)
  6922.     set_string_option(opt_idx, string, opt_flags);
  6923.     else
  6924.     {
  6925.     varp = get_varp(&options[opt_idx]);
  6926.     if (varp != NULL)    /* hidden option is not changed */
  6927.     {
  6928.         if (options[opt_idx].flags & P_NUM)
  6929.         (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
  6930.         else
  6931.         (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
  6932.     }
  6933.     }
  6934. }
  6935.  
  6936. /*
  6937.  * Get the terminal code for a terminal option.
  6938.  * Returns NULL when not found.
  6939.  */
  6940.     char_u *
  6941. get_term_code(tname)
  6942.     char_u    *tname;
  6943. {
  6944.     int        opt_idx;
  6945.     char_u  *varp;
  6946.  
  6947.     if (tname[0] != 't' || tname[1] != '_' ||
  6948.         tname[2] == NUL || tname[3] == NUL)
  6949.     return NULL;
  6950.     if ((opt_idx = findoption(tname)) >= 0)
  6951.     {
  6952.     varp = get_varp(&(options[opt_idx]));
  6953.     if (varp != NULL)
  6954.         varp = *(char_u **)(varp);
  6955.     return varp;
  6956.     }
  6957.     return find_termcode(tname + 2);
  6958. }
  6959.  
  6960.     char_u *
  6961. get_highlight_default()
  6962. {
  6963.     int i;
  6964.  
  6965.     i = findoption((char_u *)"hl");
  6966.     if (i >= 0)
  6967.     return options[i].def_val[VI_DEFAULT];
  6968.     return (char_u *)NULL;
  6969. }
  6970.  
  6971. /*
  6972.  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
  6973.  */
  6974.     static int
  6975. find_key_option(arg)
  6976.     char_u *arg;
  6977. {
  6978.     int        key;
  6979.     int        modifiers;
  6980.  
  6981.     /*
  6982.      * Don't use get_special_key_code() for t_xx, we don't want it to call
  6983.      * add_termcap_entry().
  6984.      */
  6985.     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
  6986.     key = TERMCAP2KEY(arg[2], arg[3]);
  6987.     else
  6988.     {
  6989.     --arg;                /* put arg at the '<' */
  6990.     key = find_special_key(&arg, &modifiers, TRUE);
  6991.     if (modifiers)            /* can't handle modifiers here */
  6992.         key = 0;
  6993.     }
  6994.     return key;
  6995. }
  6996.  
  6997. /*
  6998.  * if 'all' == 0: show changed options
  6999.  * if 'all' == 1: show all normal options
  7000.  * if 'all' == 2: show all terminal options
  7001.  */
  7002.     static void
  7003. showoptions(all, opt_flags)
  7004.     int        all;
  7005.     int        opt_flags;    /* OPT_LOCAL and/or OPT_GLOBAL */
  7006. {
  7007.     struct vimoption    *p;
  7008.     int            col;
  7009.     int            isterm;
  7010.     char_u        *varp;
  7011.     struct vimoption    **items;
  7012.     int            item_count;
  7013.     int            run;
  7014.     int            row, rows;
  7015.     int            cols;
  7016.     int            i;
  7017.     int            len;
  7018.  
  7019. #define INC 20
  7020. #define GAP 3
  7021.  
  7022.     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
  7023.                                 PARAM_COUNT));
  7024.     if (items == NULL)
  7025.     return;
  7026.  
  7027.     /* Highlight title */
  7028.     if (all == 2)
  7029.     MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
  7030.     else if (opt_flags & OPT_GLOBAL)
  7031.     MSG_PUTS_TITLE(_("\n--- Global option values ---"));
  7032.     else if (opt_flags & OPT_LOCAL)
  7033.     MSG_PUTS_TITLE(_("\n--- Local option values ---"));
  7034.     else
  7035.     MSG_PUTS_TITLE(_("\n--- Options ---"));
  7036.  
  7037.     /*
  7038.      * do the loop two times:
  7039.      * 1. display the short items
  7040.      * 2. display the long items (only strings and numbers)
  7041.      */
  7042.     for (run = 1; run <= 2 && !got_int; ++run)
  7043.     {
  7044.     /*
  7045.      * collect the items in items[]
  7046.      */
  7047.     item_count = 0;
  7048.     for (p = &options[0]; p->fullname != NULL; p++)
  7049.     {
  7050.         varp = NULL;
  7051.         isterm = istermoption(p);
  7052.         if (opt_flags != 0)
  7053.         {
  7054.         if (p->indir != PV_NONE && !isterm)
  7055.             varp = get_varp_scope(p, opt_flags);
  7056.         }
  7057.         else
  7058.         varp = get_varp(p);
  7059.         if (varp != NULL
  7060.             && ((all == 2 && isterm)
  7061.             || (all == 1 && !isterm)
  7062.             || (all == 0 && !optval_default(p, varp))))
  7063.         {
  7064.         if (p->flags & P_BOOL)
  7065.             len = 1;        /* a toggle option fits always */
  7066.         else
  7067.         {
  7068.             option_value2string(p, opt_flags);
  7069.             len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
  7070.         }
  7071.         if ((len <= INC - GAP && run == 1) ||
  7072.                         (len > INC - GAP && run == 2))
  7073.             items[item_count++] = p;
  7074.         }
  7075.     }
  7076.  
  7077.     /*
  7078.      * display the items
  7079.      */
  7080.     if (run == 1)
  7081.     {
  7082.         cols = (Columns + GAP - 3) / INC;
  7083.         if (cols == 0)
  7084.         cols = 1;
  7085.         rows = (item_count + cols - 1) / cols;
  7086.     }
  7087.     else    /* run == 2 */
  7088.         rows = item_count;
  7089.     for (row = 0; row < rows && !got_int; ++row)
  7090.     {
  7091.         msg_putchar('\n');            /* go to next line */
  7092.         if (got_int)            /* 'q' typed in more */
  7093.         break;
  7094.         col = 0;
  7095.         for (i = row; i < item_count; i += rows)
  7096.         {
  7097.         msg_col = col;            /* make columns */
  7098.         showoneopt(items[i], opt_flags);
  7099.         col += INC;
  7100.         }
  7101.         out_flush();
  7102.         ui_breakcheck();
  7103.     }
  7104.     }
  7105.     vim_free(items);
  7106. }
  7107.  
  7108. /*
  7109.  * Return TRUE if option "p" has its default value.
  7110.  */
  7111.     static int
  7112. optval_default(p, varp)
  7113.     struct vimoption    *p;
  7114.     char_u        *varp;
  7115. {
  7116.     int        dvi;
  7117.  
  7118.     if (varp == NULL)
  7119.     return TRUE;        /* hidden option is always at default */
  7120.     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
  7121.     if (p->flags & P_NUM)
  7122.     return (*(long *)varp == (long)p->def_val[dvi]);
  7123.     if (p->flags & P_BOOL)
  7124.             /* the cast to long is required for Manx C */
  7125.     return (*(int *)varp == (int)(long)p->def_val[dvi]);
  7126.     /* P_STRING */
  7127.     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
  7128. }
  7129.  
  7130. /*
  7131.  * showoneopt: show the value of one option
  7132.  * must not be called with a hidden option!
  7133.  */
  7134.     static void
  7135. showoneopt(p, opt_flags)
  7136.     struct vimoption    *p;
  7137.     int            opt_flags;    /* OPT_LOCAL or OPT_GLOBAL */
  7138. {
  7139.     char_u        *varp;
  7140.  
  7141.     varp = get_varp_scope(p, opt_flags);
  7142.  
  7143.     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
  7144.     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
  7145.                     ? !curbufIsChanged() : !*(int *)varp))
  7146.     MSG_PUTS("no");
  7147.     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
  7148.     MSG_PUTS("--");
  7149.     else
  7150.     MSG_PUTS("  ");
  7151.     MSG_PUTS(p->fullname);
  7152.     if (!(p->flags & P_BOOL))
  7153.     {
  7154.     msg_putchar('=');
  7155.     /* put value string in NameBuff */
  7156.     option_value2string(p, opt_flags);
  7157.     msg_outtrans(NameBuff);
  7158.     }
  7159. }
  7160.  
  7161. /*
  7162.  * Write modified options as ":set" commands to a file.
  7163.  *
  7164.  * There are three values for "opt_flags":
  7165.  * OPT_GLOBAL:           Write global option values and fresh values of
  7166.  *               buffer-local options (used for start of a session
  7167.  *               file).
  7168.  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
  7169.  *               curwin (used for a vimrc file).
  7170.  * OPT_LOCAL:           Write buffer-local option values for curbuf, fresh
  7171.  *               and local values for window-local options of
  7172.  *               curwin.  Local values are also written when at the
  7173.  *               default value, because a modeline or autocommand
  7174.  *               may have set them when doing ":edit file" and the
  7175.  *               user has set them back at the default or fresh
  7176.  *               value.
  7177.  *               When "local_only" is TRUE, don't write fresh
  7178.  *               values, only local values (for ":mkview").
  7179.  * (fresh value = value used for a new buffer or window for a local option).
  7180.  *
  7181.  * Return FAIL on error, OK otherwise.
  7182.  */
  7183.     int
  7184. makeset(fd, opt_flags, local_only)
  7185.     FILE    *fd;
  7186.     int        opt_flags;
  7187.     int        local_only;
  7188. {
  7189.     struct vimoption    *p;
  7190.     char_u        *varp;            /* currently used value */
  7191.     char_u        *varp_fresh;        /* local value */
  7192.     char_u        *varp_local = NULL;    /* fresh value */
  7193.     char        *cmd;
  7194.     int            round;
  7195.  
  7196.     /*
  7197.      * The options that don't have a default (terminal name, columns, lines)
  7198.      * are never written.  Terminal options are also not written.
  7199.      */
  7200.     for (p = &options[0]; !istermoption(p); p++)
  7201.     if (!(p->flags & P_NO_MKRC) && !istermoption(p))
  7202.     {
  7203.         /* skip global option when only doing locals */
  7204.         if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
  7205.         continue;
  7206.  
  7207.         /* Global values are only written when not at the default value. */
  7208.         varp = get_varp_scope(p, opt_flags);
  7209.         if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
  7210.         continue;
  7211.  
  7212.         round = 2;
  7213.         if (p->indir != PV_NONE)
  7214.         {
  7215.         if (p->var == VAR_WIN)
  7216.         {
  7217.             /* skip window-local option when only doing globals */
  7218.             if (!(opt_flags & OPT_LOCAL))
  7219.             continue;
  7220.             /* When fresh value of window-local option is not at the
  7221.              * default, need to write it too. */
  7222.             if (!(opt_flags & OPT_GLOBAL) && !local_only)
  7223.             {
  7224.             varp_fresh = get_varp_scope(p, OPT_GLOBAL);
  7225.             if (!optval_default(p, varp_fresh))
  7226.             {
  7227.                 round = 1;
  7228.                 varp_local = varp;
  7229.                 varp = varp_fresh;
  7230.             }
  7231.             }
  7232.         }
  7233.         }
  7234.  
  7235.         /* Round 1: fresh value for window-local options.
  7236.          * Round 2: other values */
  7237.         for ( ; round <= 2; varp = varp_local, ++round)
  7238.         {
  7239.         if (round == 1 || (opt_flags & OPT_GLOBAL))
  7240.             cmd = "set";
  7241.         else
  7242.             cmd = "setlocal";
  7243.  
  7244.         if (p->flags & P_BOOL)
  7245.         {
  7246.             if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
  7247.             return FAIL;
  7248.         }
  7249.         else if (p->flags & P_NUM)
  7250.         {
  7251.             if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
  7252.             return FAIL;
  7253.         }
  7254.         else    /* P_STRING */
  7255.         {
  7256.             /* Don't set 'syntax' and 'filetype' again if the value is
  7257.              * already right, avoids reloading the syntax file. */
  7258.             if (p->indir == PV_SYN || p->indir == PV_FT)
  7259.             {
  7260.             if (fprintf(fd, "if &%s != '%s'", p->fullname,
  7261.                                *(char_u **)(varp)) < 0
  7262.                 || put_eol(fd) < 0)
  7263.                 return FAIL;
  7264.             }
  7265.             if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
  7266.                       (p->flags & P_EXPAND) != 0) == FAIL)
  7267.             return FAIL;
  7268.             if (p->indir == PV_SYN || p->indir == PV_FT)
  7269.             {
  7270.             if (put_line(fd, "endif") == FAIL)
  7271.                 return FAIL;
  7272.             }
  7273.         }
  7274.         }
  7275.     }
  7276.     return OK;
  7277. }
  7278.  
  7279. #if defined(FEAT_FOLDING) || defined(PROTO)
  7280. /*
  7281.  * Generate set commands for the local fold options only.  Used when
  7282.  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
  7283.  */
  7284.     int
  7285. makefoldset(fd)
  7286.     FILE    *fd;
  7287. {
  7288.     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
  7289. # ifdef FEAT_EVAL
  7290.         || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
  7291.                                        == FAIL
  7292. # endif
  7293.         || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
  7294.                                        == FAIL
  7295.         || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
  7296.                                        == FAIL
  7297.         || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
  7298.         || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
  7299.         || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
  7300.         || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
  7301.         )
  7302.     return FAIL;
  7303.  
  7304.     return OK;
  7305. }
  7306. #endif
  7307.  
  7308.     static int
  7309. put_setstring(fd, cmd, name, valuep, expand)
  7310.     FILE    *fd;
  7311.     char    *cmd;
  7312.     char    *name;
  7313.     char_u    **valuep;
  7314.     int        expand;
  7315. {
  7316.     char_u    *s;
  7317.     char_u    buf[MAXPATHL];
  7318.  
  7319.     if (fprintf(fd, "%s %s=", cmd, name) < 0)
  7320.     return FAIL;
  7321.     if (*valuep != NULL)
  7322.     {
  7323.     /* Output 'pastetoggle' as key names.  For other
  7324.      * options some characters have to be escaped with
  7325.      * CTRL-V or backslash */
  7326.     if (valuep == &p_pt)
  7327.     {
  7328.         s = *valuep;
  7329.         while (*s != NUL)
  7330.         if (fputs((char *)str2special(&s, FALSE), fd) < 0)
  7331.             return FAIL;
  7332.     }
  7333.     else if (expand)
  7334.     {
  7335.         home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
  7336.         if (put_escstr(fd, buf, 2) == FAIL)
  7337.         return FAIL;
  7338.     }
  7339.     else if (put_escstr(fd, *valuep, 2) == FAIL)
  7340.         return FAIL;
  7341.     }
  7342.     if (put_eol(fd) < 0)
  7343.     return FAIL;
  7344.     return OK;
  7345. }
  7346.  
  7347.     static int
  7348. put_setnum(fd, cmd, name, valuep)
  7349.     FILE    *fd;
  7350.     char    *cmd;
  7351.     char    *name;
  7352.     long    *valuep;
  7353. {
  7354.     long    wc;
  7355.  
  7356.     if (fprintf(fd, "%s %s=", cmd, name) < 0)
  7357.     return FAIL;
  7358.     if (wc_use_keyname((char_u *)valuep, &wc))
  7359.     {
  7360.     /* print 'wildchar' and 'wildcharm' as a key name */
  7361.     if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
  7362.         return FAIL;
  7363.     }
  7364.     else if (fprintf(fd, "%ld", *valuep) < 0)
  7365.     return FAIL;
  7366.     if (put_eol(fd) < 0)
  7367.     return FAIL;
  7368.     return OK;
  7369. }
  7370.  
  7371.     static int
  7372. put_setbool(fd, cmd, name, value)
  7373.     FILE    *fd;
  7374.     char    *cmd;
  7375.     char    *name;
  7376.     int        value;
  7377. {
  7378.     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
  7379.         || put_eol(fd) < 0)
  7380.     return FAIL;
  7381.     return OK;
  7382. }
  7383.  
  7384. /*
  7385.  * Clear all the terminal options.
  7386.  * If the option has been allocated, free the memory.
  7387.  * Terminal options are never hidden or indirect.
  7388.  */
  7389.     void
  7390. clear_termoptions()
  7391. {
  7392.     struct vimoption   *p;
  7393.  
  7394.     /*
  7395.      * Reset a few things before clearing the old options. This may cause
  7396.      * outputting a few things that the terminal doesn't understand, but the
  7397.      * screen will be cleared later, so this is OK.
  7398.      */
  7399. #ifdef FEAT_MOUSE_TTY
  7400.     mch_setmouse(FALSE);        /* switch mouse off */
  7401. #endif
  7402. #ifdef FEAT_TITLE
  7403.     mch_restore_title(3);        /* restore window titles */
  7404. #endif
  7405. #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
  7406.     /* When starting the GUI close the display opened for the clipboard.
  7407.      * After restoring the title, because that will need the display. */
  7408.     if (gui.starting)
  7409.     clear_xterm_clip();
  7410. #endif
  7411. #ifdef WIN3264
  7412.     /*
  7413.      * Check if this is allowed now.
  7414.      */
  7415.     if (can_end_termcap_mode(FALSE) == TRUE)
  7416. #endif
  7417.     stoptermcap();            /* stop termcap mode */
  7418.  
  7419.     for (p = &options[0]; p->fullname != NULL; p++)
  7420.     if (istermoption(p))
  7421.     {
  7422.         if (p->flags & P_ALLOCED)
  7423.         free_string_option(*(char_u **)(p->var));
  7424.         if (p->flags & P_DEF_ALLOCED)
  7425.         free_string_option(p->def_val[VI_DEFAULT]);
  7426.         *(char_u **)(p->var) = empty_option;
  7427.         p->def_val[VI_DEFAULT] = empty_option;
  7428.         p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
  7429.     }
  7430.     clear_termcodes();
  7431. }
  7432.  
  7433. /*
  7434.  * Set the terminal option defaults to the current value.
  7435.  * Used after setting the terminal name.
  7436.  */
  7437.     void
  7438. set_term_defaults()
  7439. {
  7440.     struct vimoption   *p;
  7441.  
  7442.     for (p = &options[0]; p->fullname != NULL; p++)
  7443.     {
  7444.     if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
  7445.     {
  7446.         if (p->flags & P_DEF_ALLOCED)
  7447.         {
  7448.         free_string_option(p->def_val[VI_DEFAULT]);
  7449.         p->flags &= ~P_DEF_ALLOCED;
  7450.         }
  7451.         p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
  7452.         if (p->flags & P_ALLOCED)
  7453.         {
  7454.         p->flags |= P_DEF_ALLOCED;
  7455.         p->flags &= ~P_ALLOCED;     /* don't free the value now */
  7456.         }
  7457.     }
  7458.     }
  7459. }
  7460.  
  7461. /*
  7462.  * return TRUE if 'p' starts with 't_'
  7463.  */
  7464.     static int
  7465. istermoption(p)
  7466.     struct vimoption *p;
  7467. {
  7468.     return (p->fullname[0] == 't' && p->fullname[1] == '_');
  7469. }
  7470.  
  7471. /*
  7472.  * Compute columns for ruler and shown command. 'sc_col' is also used to
  7473.  * decide what the maximum length of a message on the status line can be.
  7474.  * If there is a status line for the last window, 'sc_col' is independent
  7475.  * of 'ru_col'.
  7476.  */
  7477.  
  7478. #define COL_RULER 17        /* columns needed by standard ruler */
  7479.  
  7480.     void
  7481. comp_col()
  7482. {
  7483. #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
  7484.     int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
  7485.  
  7486.     sc_col = 0;
  7487.     ru_col = 0;
  7488.     if (p_ru)
  7489.     {
  7490. #ifdef FEAT_STL_OPT
  7491.     ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
  7492. #else
  7493.     ru_col = COL_RULER + 1;
  7494. #endif
  7495.     /* no last status line, adjust sc_col */
  7496.     if (!last_has_status)
  7497.         sc_col = ru_col;
  7498.     }
  7499.     if (p_sc)
  7500.     {
  7501.     sc_col += SHOWCMD_COLS;
  7502.     if (!p_ru || last_has_status)        /* no need for separating space */
  7503.         ++sc_col;
  7504.     }
  7505.     sc_col = Columns - sc_col;
  7506.     ru_col = Columns - ru_col;
  7507.     if (sc_col <= 0)        /* screen too narrow, will become a mess */
  7508.     sc_col = 1;
  7509.     if (ru_col <= 0)
  7510.     ru_col = 1;
  7511. #else
  7512.     sc_col = Columns;
  7513.     ru_col = Columns;
  7514. #endif
  7515. }
  7516.  
  7517. /*
  7518.  * Get pointer to option variable, depending on local or global scope.
  7519.  */
  7520.     static char_u *
  7521. get_varp_scope(p, opt_flags)
  7522.     struct vimoption    *p;
  7523.     int            opt_flags;
  7524. {
  7525.     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
  7526.     {
  7527.     if (p->var == VAR_WIN)
  7528.         return (char_u *)GLOBAL_WO(get_varp(p));
  7529.     return p->var;
  7530.     }
  7531.     if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
  7532.     {
  7533.     switch ((int)p->indir)
  7534.     {
  7535. #ifdef FEAT_QUICKFIX
  7536.         case OPT_BOTH(PV_GP):   return (char_u *)&(curbuf->b_p_gp);
  7537.         case OPT_BOTH(PV_MP):   return (char_u *)&(curbuf->b_p_mp);
  7538.         case OPT_BOTH(PV_EFM):  return (char_u *)&(curbuf->b_p_efm);
  7539. #endif
  7540.         case OPT_BOTH(PV_EP):   return (char_u *)&(curbuf->b_p_ep);
  7541.         case OPT_BOTH(PV_KP):   return (char_u *)&(curbuf->b_p_kp);
  7542.         case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
  7543.         case OPT_BOTH(PV_AR):   return (char_u *)&(curbuf->b_p_ar);
  7544.         case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
  7545. #ifdef FEAT_FIND_ID
  7546.         case OPT_BOTH(PV_DEF):  return (char_u *)&(curbuf->b_p_def);
  7547.         case OPT_BOTH(PV_INC):  return (char_u *)&(curbuf->b_p_inc);
  7548. #endif
  7549. #ifdef FEAT_INS_EXPAND
  7550.         case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
  7551.         case OPT_BOTH(PV_TSR):  return (char_u *)&(curbuf->b_p_tsr);
  7552. #endif
  7553.     }
  7554.     return NULL; /* "cannot happen" */
  7555.     }
  7556.     return get_varp(p);
  7557. }
  7558.  
  7559. /*
  7560.  * Get pointer to option variable.
  7561.  */
  7562.     static char_u *
  7563. get_varp(p)
  7564.     struct vimoption    *p;
  7565. {
  7566.     /* hidden option, always return NULL */
  7567.     if (p->var == NULL)
  7568.     return NULL;
  7569.  
  7570.     switch ((int)p->indir)
  7571.     {
  7572.     case PV_NONE:    return p->var;
  7573.  
  7574.     /* global option with local value: use local value if it's been set */
  7575.     case OPT_BOTH(PV_EP):    return *curbuf->b_p_ep != NUL
  7576.                     ? (char_u *)&curbuf->b_p_ep : p->var;
  7577.     case OPT_BOTH(PV_KP):    return *curbuf->b_p_kp != NUL
  7578.                     ? (char_u *)&curbuf->b_p_kp : p->var;
  7579.     case OPT_BOTH(PV_PATH):    return *curbuf->b_p_path != NUL
  7580.                     ? (char_u *)&(curbuf->b_p_path) : p->var;
  7581.     case OPT_BOTH(PV_AR):    return curbuf->b_p_ar >= 0
  7582.                     ? (char_u *)&(curbuf->b_p_ar) : p->var;
  7583.     case OPT_BOTH(PV_TAGS):    return *curbuf->b_p_tags != NUL
  7584.                     ? (char_u *)&(curbuf->b_p_tags) : p->var;
  7585. #ifdef FEAT_FIND_ID
  7586.     case OPT_BOTH(PV_DEF):    return *curbuf->b_p_def != NUL
  7587.                     ? (char_u *)&(curbuf->b_p_def) : p->var;
  7588.     case OPT_BOTH(PV_INC):    return *curbuf->b_p_inc != NUL
  7589.                     ? (char_u *)&(curbuf->b_p_inc) : p->var;
  7590. #endif
  7591. #ifdef FEAT_INS_EXPAND
  7592.     case OPT_BOTH(PV_DICT):    return *curbuf->b_p_dict != NUL
  7593.                     ? (char_u *)&(curbuf->b_p_dict) : p->var;
  7594.     case OPT_BOTH(PV_TSR):    return *curbuf->b_p_tsr != NUL
  7595.                     ? (char_u *)&(curbuf->b_p_tsr) : p->var;
  7596. #endif
  7597. #ifdef FEAT_QUICKFIX
  7598.     case OPT_BOTH(PV_GP):    return *curbuf->b_p_gp != NUL
  7599.                     ? (char_u *)&(curbuf->b_p_gp) : p->var;
  7600.     case OPT_BOTH(PV_MP):    return *curbuf->b_p_mp != NUL
  7601.                     ? (char_u *)&(curbuf->b_p_mp) : p->var;
  7602.     case OPT_BOTH(PV_EFM):    return *curbuf->b_p_efm != NUL
  7603.                     ? (char_u *)&(curbuf->b_p_efm) : p->var;
  7604. #endif
  7605.  
  7606. #ifdef FEAT_ARABIC
  7607.     case PV_ARAB:    return (char_u *)&(curwin->w_p_arab);
  7608. #endif
  7609.     case PV_LIST:    return (char_u *)&(curwin->w_p_list);
  7610. #ifdef FEAT_DIFF
  7611.     case PV_DIFF:    return (char_u *)&(curwin->w_p_diff);
  7612. #endif
  7613. #ifdef FEAT_FOLDING
  7614.     case PV_FDC:    return (char_u *)&(curwin->w_p_fdc);
  7615.     case PV_FEN:    return (char_u *)&(curwin->w_p_fen);
  7616.     case PV_FDI:    return (char_u *)&(curwin->w_p_fdi);
  7617.     case PV_FDL:    return (char_u *)&(curwin->w_p_fdl);
  7618.     case PV_FDM:    return (char_u *)&(curwin->w_p_fdm);
  7619.     case PV_FML:    return (char_u *)&(curwin->w_p_fml);
  7620.     case PV_FDN:    return (char_u *)&(curwin->w_p_fdn);
  7621. # ifdef FEAT_EVAL
  7622.     case PV_FDE:    return (char_u *)&(curwin->w_p_fde);
  7623.     case PV_FDT:    return (char_u *)&(curwin->w_p_fdt);
  7624. # endif
  7625.     case PV_FMR:    return (char_u *)&(curwin->w_p_fmr);
  7626. #endif
  7627.     case PV_NU:    return (char_u *)&(curwin->w_p_nu);
  7628. #if defined(FEAT_WINDOWS)
  7629.     case PV_WFH:    return (char_u *)&(curwin->w_p_wfh);
  7630. #endif
  7631. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  7632.     case PV_PVW:    return (char_u *)&(curwin->w_p_pvw);
  7633. #endif
  7634. #ifdef FEAT_RIGHTLEFT
  7635.     case PV_RL:    return (char_u *)&(curwin->w_p_rl);
  7636.     case PV_RLC:    return (char_u *)&(curwin->w_p_rlc);
  7637. #endif
  7638.     case PV_SCROLL:    return (char_u *)&(curwin->w_p_scr);
  7639.     case PV_WRAP:    return (char_u *)&(curwin->w_p_wrap);
  7640. #ifdef FEAT_LINEBREAK
  7641.     case PV_LBR:    return (char_u *)&(curwin->w_p_lbr);
  7642. #endif
  7643. #ifdef FEAT_SCROLLBIND
  7644.     case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
  7645. #endif
  7646.  
  7647.     case PV_AI:    return (char_u *)&(curbuf->b_p_ai);
  7648.     case PV_BIN:    return (char_u *)&(curbuf->b_p_bin);
  7649. #ifdef FEAT_MBYTE
  7650.     case PV_BOMB:    return (char_u *)&(curbuf->b_p_bomb);
  7651. #endif
  7652. #if defined(FEAT_QUICKFIX)
  7653.     case PV_BH:    return (char_u *)&(curbuf->b_p_bh);
  7654.     case PV_BT:    return (char_u *)&(curbuf->b_p_bt);
  7655. #endif
  7656.     case PV_BL:    return (char_u *)&(curbuf->b_p_bl);
  7657.     case PV_CI:    return (char_u *)&(curbuf->b_p_ci);
  7658. #ifdef FEAT_CINDENT
  7659.     case PV_CIN:    return (char_u *)&(curbuf->b_p_cin);
  7660.     case PV_CINK:    return (char_u *)&(curbuf->b_p_cink);
  7661.     case PV_CINO:    return (char_u *)&(curbuf->b_p_cino);
  7662. #endif
  7663. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  7664.     case PV_CINW:    return (char_u *)&(curbuf->b_p_cinw);
  7665. #endif
  7666. #ifdef FEAT_COMMENTS
  7667.     case PV_COM:    return (char_u *)&(curbuf->b_p_com);
  7668. #endif
  7669. #ifdef FEAT_FOLDING
  7670.     case PV_CMS:    return (char_u *)&(curbuf->b_p_cms);
  7671. #endif
  7672. #ifdef FEAT_INS_EXPAND
  7673.     case PV_CPT:    return (char_u *)&(curbuf->b_p_cpt);
  7674. #endif
  7675.     case PV_EOL:    return (char_u *)&(curbuf->b_p_eol);
  7676.     case PV_ET:    return (char_u *)&(curbuf->b_p_et);
  7677. #ifdef FEAT_MBYTE
  7678.     case PV_FENC:    return (char_u *)&(curbuf->b_p_fenc);
  7679. #endif
  7680.     case PV_FF:    return (char_u *)&(curbuf->b_p_ff);
  7681. #ifdef FEAT_AUTOCMD
  7682.     case PV_FT:    return (char_u *)&(curbuf->b_p_ft);
  7683. #endif
  7684.     case PV_FO:    return (char_u *)&(curbuf->b_p_fo);
  7685.     case PV_IMI:    return (char_u *)&(curbuf->b_p_iminsert);
  7686.     case PV_IMS:    return (char_u *)&(curbuf->b_p_imsearch);
  7687.     case PV_INF:    return (char_u *)&(curbuf->b_p_inf);
  7688.     case PV_ISK:    return (char_u *)&(curbuf->b_p_isk);
  7689. #ifdef FEAT_FIND_ID
  7690. # ifdef FEAT_EVAL
  7691.     case PV_INEX:    return (char_u *)&(curbuf->b_p_inex);
  7692. # endif
  7693. #endif
  7694. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  7695.     case PV_INDE:    return (char_u *)&(curbuf->b_p_inde);
  7696.     case PV_INDK:    return (char_u *)&(curbuf->b_p_indk);
  7697. #endif
  7698. #ifdef FEAT_CRYPT
  7699.     case PV_KEY:    return (char_u *)&(curbuf->b_p_key);
  7700. #endif
  7701. #ifdef FEAT_LISP
  7702.     case PV_LISP:    return (char_u *)&(curbuf->b_p_lisp);
  7703. #endif
  7704.     case PV_ML:    return (char_u *)&(curbuf->b_p_ml);
  7705.     case PV_MPS:    return (char_u *)&(curbuf->b_p_mps);
  7706.     case PV_MA:    return (char_u *)&(curbuf->b_p_ma);
  7707.     case PV_MOD:    return (char_u *)&(curbuf->b_changed);
  7708.     case PV_NF:    return (char_u *)&(curbuf->b_p_nf);
  7709. #ifdef FEAT_OSFILETYPE
  7710.     case PV_OFT:    return (char_u *)&(curbuf->b_p_oft);
  7711. #endif
  7712.     case PV_PI:    return (char_u *)&(curbuf->b_p_pi);
  7713.     case PV_RO:    return (char_u *)&(curbuf->b_p_ro);
  7714. #ifdef FEAT_SMARTINDENT
  7715.     case PV_SI:    return (char_u *)&(curbuf->b_p_si);
  7716. #endif
  7717. #ifndef SHORT_FNAME
  7718.     case PV_SN:    return (char_u *)&(curbuf->b_p_sn);
  7719. #endif
  7720.     case PV_STS:    return (char_u *)&(curbuf->b_p_sts);
  7721. #ifdef FEAT_SEARCHPATH
  7722.     case PV_SUA:    return (char_u *)&(curbuf->b_p_sua);
  7723. #endif
  7724.     case PV_SWF:    return (char_u *)&(curbuf->b_p_swf);
  7725. #ifdef FEAT_SYN_HL
  7726.     case PV_SYN:    return (char_u *)&(curbuf->b_p_syn);
  7727. #endif
  7728.     case PV_SW:    return (char_u *)&(curbuf->b_p_sw);
  7729.     case PV_TS:    return (char_u *)&(curbuf->b_p_ts);
  7730.     case PV_TW:    return (char_u *)&(curbuf->b_p_tw);
  7731.     case PV_TX:    return (char_u *)&(curbuf->b_p_tx);
  7732.     case PV_WM:    return (char_u *)&(curbuf->b_p_wm);
  7733. #ifdef FEAT_KEYMAP
  7734.     case PV_KMAP:    return (char_u *)&(curbuf->b_p_keymap);
  7735. #endif
  7736.     default:    EMSG(_("E356: get_varp ERROR"));
  7737.     }
  7738.     /* always return a valid pointer to avoid a crash! */
  7739.     return (char_u *)&(curbuf->b_p_wm);
  7740. }
  7741.  
  7742. /*
  7743.  * Get the value of 'equalprg', either the buffer-local one or the global one.
  7744.  */
  7745.     char_u *
  7746. get_equalprg()
  7747. {
  7748.     if (*curbuf->b_p_ep == NUL)
  7749.     return p_ep;
  7750.     return curbuf->b_p_ep;
  7751. }
  7752.  
  7753. #if defined(FEAT_WINDOWS) || defined(PROTO)
  7754. /*
  7755.  * Copy options from one window to another.
  7756.  * Used when splitting a window.
  7757.  */
  7758.     void
  7759. win_copy_options(wp_from, wp_to)
  7760.     win_T    *wp_from;
  7761.     win_T    *wp_to;
  7762. {
  7763.     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
  7764.     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
  7765. # ifdef FEAT_RIGHTLEFT
  7766. #  ifdef FEAT_FKMAP
  7767.     /* Is this right? */
  7768.     wp_to->w_farsi = wp_from->w_farsi;
  7769. #  endif
  7770. # endif
  7771. }
  7772. #endif
  7773.  
  7774. /*
  7775.  * Copy the options from one winopt_T to another.
  7776.  * Doesn't free the old option values in "to", use clear_winopt() for that.
  7777.  * The 'scroll' option is not copied, because it depends on the window height.
  7778.  * The 'previewwindow' option is reset, there can be only one preview window.
  7779.  */
  7780.     void
  7781. copy_winopt(from, to)
  7782.     winopt_T    *from;
  7783.     winopt_T    *to;
  7784. {
  7785. #ifdef FEAT_ARABIC
  7786.     to->wo_arab = from->wo_arab;
  7787. #endif
  7788.     to->wo_list = from->wo_list;
  7789.     to->wo_nu = from->wo_nu;
  7790. #ifdef FEAT_RIGHTLEFT
  7791.     to->wo_rl  = from->wo_rl;
  7792.     to->wo_rlc = vim_strsave(from->wo_rlc);
  7793. #endif
  7794.     to->wo_wrap = from->wo_wrap;
  7795. #ifdef FEAT_LINEBREAK
  7796.     to->wo_lbr = from->wo_lbr;
  7797. #endif
  7798. #ifdef FEAT_SCROLLBIND
  7799.     to->wo_scb = from->wo_scb;
  7800. #endif
  7801. #ifdef FEAT_DIFF
  7802.     to->wo_diff = from->wo_diff;
  7803. #endif
  7804. #ifdef FEAT_FOLDING
  7805.     to->wo_fdc = from->wo_fdc;
  7806.     to->wo_fen = from->wo_fen;
  7807.     to->wo_fdi = vim_strsave(from->wo_fdi);
  7808.     to->wo_fml = from->wo_fml;
  7809.     to->wo_fdl = from->wo_fdl;
  7810.     to->wo_fdm = vim_strsave(from->wo_fdm);
  7811.     to->wo_fdn = from->wo_fdn;
  7812. # ifdef FEAT_EVAL
  7813.     to->wo_fde = vim_strsave(from->wo_fde);
  7814.     to->wo_fdt = vim_strsave(from->wo_fdt);
  7815. # endif
  7816.     to->wo_fmr = vim_strsave(from->wo_fmr);
  7817. #endif
  7818.     check_winopt(to);        /* don't want NULL pointers */
  7819. }
  7820.  
  7821. /*
  7822.  * Check string options in a window for a NULL value.
  7823.  */
  7824.     void
  7825. check_win_options(win)
  7826.     win_T    *win;
  7827. {
  7828.     check_winopt(&win->w_onebuf_opt);
  7829.     check_winopt(&win->w_allbuf_opt);
  7830. }
  7831.  
  7832. /*
  7833.  * Check for NULL pointers in a winopt_T and replace them with empty_option.
  7834.  */
  7835. /*ARGSUSED*/
  7836.     void
  7837. check_winopt(wop)
  7838.     winopt_T    *wop;
  7839. {
  7840. #ifdef FEAT_FOLDING
  7841.     check_string_option(&wop->wo_fdi);
  7842.     check_string_option(&wop->wo_fdm);
  7843. # ifdef FEAT_EVAL
  7844.     check_string_option(&wop->wo_fde);
  7845.     check_string_option(&wop->wo_fdt);
  7846. # endif
  7847.     check_string_option(&wop->wo_fmr);
  7848. #endif
  7849. #ifdef FEAT_RIGHTLEFT
  7850.     check_string_option(&wop->wo_rlc);
  7851. #endif
  7852. }
  7853.  
  7854. /*
  7855.  * Free the allocated memory inside a winopt_T.
  7856.  */
  7857. /*ARGSUSED*/
  7858.     void
  7859. clear_winopt(wop)
  7860.     winopt_T    *wop;
  7861. {
  7862. #ifdef FEAT_FOLDING
  7863.     clear_string_option(&wop->wo_fdi);
  7864.     clear_string_option(&wop->wo_fdm);
  7865. # ifdef FEAT_EVAL
  7866.     clear_string_option(&wop->wo_fde);
  7867.     clear_string_option(&wop->wo_fdt);
  7868. # endif
  7869.     clear_string_option(&wop->wo_fmr);
  7870. #endif
  7871. #ifdef FEAT_RIGHTLEFT
  7872.     clear_string_option(&wop->wo_rlc);
  7873. #endif
  7874. }
  7875.  
  7876. /*
  7877.  * Copy global option values to local options for one buffer.
  7878.  * Used when creating a new buffer and sometimes when entering a buffer.
  7879.  * flags:
  7880.  * BCO_ENTER    We will enter the buf buffer.
  7881.  * BCO_ALWAYS    Always copy the options, but only set b_p_initialized when
  7882.  *        appropriate.
  7883.  * BCO_NOHELP    Don't copy the values to a help buffer.
  7884.  */
  7885.     void
  7886. buf_copy_options(buf, flags)
  7887.     buf_T    *buf;
  7888.     int        flags;
  7889. {
  7890.     int        should_copy = TRUE;
  7891.     char_u    *save_p_isk = NULL;        /* init for GCC */
  7892.     int        dont_do_help;
  7893.     int        did_isk = FALSE;
  7894.  
  7895.     /*
  7896.      * Don't do anything of the buffer is invalid.
  7897.      */
  7898.     if (buf == NULL || !buf_valid(buf))
  7899.     return;
  7900.  
  7901.     /*
  7902.      * Skip this when the option defaults have not been set yet.  Happens when
  7903.      * main() allocates the first buffer.
  7904.      */
  7905.     if (p_cpo != NULL)
  7906.     {
  7907.     /*
  7908.      * Always copy when entering and 'cpo' contains 'S'.
  7909.      * Don't copy when already initialized.
  7910.      * Don't copy when 'cpo' contains 's' and not entering.
  7911.      * 'S'    BCO_ENTER  initialized    's'  should_copy
  7912.      * yes      yes           X     X    TRUE
  7913.      * yes      no          yes     X    FALSE
  7914.      * no       X          yes     X    FALSE
  7915.      *  X      no          no    yes    FALSE
  7916.      *  X      no          no    no    TRUE
  7917.      * no      yes          no     X    TRUE
  7918.      */
  7919.     if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
  7920.         && (buf->b_p_initialized
  7921.             || (!(flags & BCO_ENTER)
  7922.             && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
  7923.         should_copy = FALSE;
  7924.  
  7925.     if (should_copy || (flags & BCO_ALWAYS))
  7926.     {
  7927.         /* Don't copy the options specific to a help buffer when
  7928.          * BCO_NOHELP is given or the options were initialized already
  7929.          * (jumping back to a help file with CTRL-T or CTRL-O) */
  7930.         dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
  7931.                                || buf->b_p_initialized;
  7932.         if (dont_do_help)        /* don't free b_p_isk */
  7933.         {
  7934.         save_p_isk = buf->b_p_isk;
  7935.         buf->b_p_isk = NULL;
  7936.         }
  7937.         /*
  7938.          * Always free the allocated strings.
  7939.          * If not already initialized, set 'readonly' and copy 'fileformat'.
  7940.          */
  7941.         if (!buf->b_p_initialized)
  7942.         {
  7943.         free_buf_options(buf, TRUE);
  7944.         buf->b_p_ro = FALSE;        /* don't copy readonly */
  7945.         buf->b_p_tx = p_tx;
  7946. #ifdef FEAT_MBYTE
  7947.         buf->b_p_fenc = vim_strsave(p_fenc);
  7948. #endif
  7949.         buf->b_p_ff = vim_strsave(p_ff);
  7950. #if defined(FEAT_QUICKFIX)
  7951.         buf->b_p_bh = empty_option;
  7952.         buf->b_p_bt = empty_option;
  7953. #endif
  7954.         }
  7955.         else
  7956.         free_buf_options(buf, FALSE);
  7957.  
  7958.         buf->b_p_ai = p_ai;
  7959.         buf->b_p_ai_nopaste = p_ai_nopaste;
  7960.         buf->b_p_sw = p_sw;
  7961.         buf->b_p_tw = p_tw;
  7962.         buf->b_p_tw_nopaste = p_tw_nopaste;
  7963.         buf->b_p_tw_nobin = p_tw_nobin;
  7964.         buf->b_p_wm = p_wm;
  7965.         buf->b_p_wm_nopaste = p_wm_nopaste;
  7966.         buf->b_p_wm_nobin = p_wm_nobin;
  7967.         buf->b_p_bin = p_bin;
  7968.         buf->b_p_et = p_et;
  7969.         buf->b_p_et_nobin = p_et_nobin;
  7970.         buf->b_p_ml = p_ml;
  7971.         buf->b_p_ml_nobin = p_ml_nobin;
  7972.         buf->b_p_inf = p_inf;
  7973.         buf->b_p_swf = p_swf;
  7974. #ifdef FEAT_INS_EXPAND
  7975.         buf->b_p_cpt = vim_strsave(p_cpt);
  7976. #endif
  7977.         buf->b_p_sts = p_sts;
  7978.         buf->b_p_sts_nopaste = p_sts_nopaste;
  7979. #ifndef SHORT_FNAME
  7980.         buf->b_p_sn = p_sn;
  7981. #endif
  7982. #ifdef FEAT_COMMENTS
  7983.         buf->b_p_com = vim_strsave(p_com);
  7984. #endif
  7985. #ifdef FEAT_FOLDING
  7986.         buf->b_p_cms = vim_strsave(p_cms);
  7987. #endif
  7988.         buf->b_p_fo = vim_strsave(p_fo);
  7989.         buf->b_p_nf = vim_strsave(p_nf);
  7990.         buf->b_p_mps = vim_strsave(p_mps);
  7991. #ifdef FEAT_SMARTINDENT
  7992.         buf->b_p_si = p_si;
  7993. #endif
  7994.         buf->b_p_ci = p_ci;
  7995. #ifdef FEAT_CINDENT
  7996.         buf->b_p_cin = p_cin;
  7997.         buf->b_p_cink = vim_strsave(p_cink);
  7998.         buf->b_p_cino = vim_strsave(p_cino);
  7999. #endif
  8000. #ifdef FEAT_AUTOCMD
  8001.         /* Don't copy 'filetype', it must be detected */
  8002.         buf->b_p_ft = empty_option;
  8003. #endif
  8004. #ifdef FEAT_OSFILETYPE
  8005.         buf->b_p_oft = vim_strsave(p_oft);
  8006. #endif
  8007.         buf->b_p_pi = p_pi;
  8008. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  8009.         buf->b_p_cinw = vim_strsave(p_cinw);
  8010. #endif
  8011. #ifdef FEAT_LISP
  8012.         buf->b_p_lisp = p_lisp;
  8013. #endif
  8014. #ifdef FEAT_SYN_HL
  8015.         /* Don't copy 'syntax', it must be set */
  8016.         buf->b_p_syn = empty_option;
  8017. #endif
  8018. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  8019.         buf->b_p_inde = vim_strsave(p_inde);
  8020.         buf->b_p_indk = vim_strsave(p_indk);
  8021. #endif
  8022. #ifdef FEAT_CRYPT
  8023.         buf->b_p_key = vim_strsave(p_key);
  8024. #endif
  8025. #ifdef FEAT_SEARCHPATH
  8026.         buf->b_p_sua = vim_strsave(p_sua);
  8027. #endif
  8028. #ifdef FEAT_KEYMAP
  8029.         buf->b_p_keymap = vim_strsave(p_keymap);
  8030.         buf->b_kmap_state |= KEYMAP_INIT;
  8031. #endif
  8032.         /* This isn't really an option, but copying the langmap and IME
  8033.          * state from the current buffer is better than resetting it. */
  8034.         buf->b_p_iminsert = p_iminsert;
  8035.         buf->b_p_imsearch = p_imsearch;
  8036.  
  8037.         /* options that are normally global but also have a local value
  8038.          * are not copied, start using the global value */
  8039.         buf->b_p_ar = -1;
  8040. #ifdef FEAT_QUICKFIX
  8041.         buf->b_p_gp = empty_option;
  8042.         buf->b_p_mp = empty_option;
  8043.         buf->b_p_efm = empty_option;
  8044. #endif
  8045.         buf->b_p_ep = empty_option;
  8046.         buf->b_p_kp = empty_option;
  8047.         buf->b_p_path = empty_option;
  8048.         buf->b_p_tags = empty_option;
  8049. #ifdef FEAT_FIND_ID
  8050.         buf->b_p_def = empty_option;
  8051.         buf->b_p_inc = empty_option;
  8052. # ifdef FEAT_EVAL
  8053.         buf->b_p_inex = vim_strsave(p_inex);
  8054. # endif
  8055. #endif
  8056. #ifdef FEAT_INS_EXPAND
  8057.         buf->b_p_dict = empty_option;
  8058.         buf->b_p_tsr = empty_option;
  8059. #endif
  8060.  
  8061.         /*
  8062.          * Don't copy the options set by ex_help(), use the saved values,
  8063.          * when going from a help buffer to a non-help buffer.
  8064.          * Don't touch these at all when BCO_NOHELP is used and going from
  8065.          * or to a help buffer.
  8066.          */
  8067.         if (dont_do_help)
  8068.         buf->b_p_isk = save_p_isk;
  8069.         else
  8070.         {
  8071.         buf->b_p_isk = vim_strsave(p_isk);
  8072.         did_isk = TRUE;
  8073.         buf->b_p_ts = p_ts;
  8074.         buf->b_help = FALSE;
  8075. #ifdef FEAT_QUICKFIX
  8076.         if (buf->b_p_bt[0] == 'h')
  8077.             clear_string_option(&buf->b_p_bt);
  8078. #endif
  8079.         buf->b_p_ma = p_ma;
  8080.         }
  8081.     }
  8082.  
  8083.     /*
  8084.      * When the options should be copied (ignoring BCO_ALWAYS), set the
  8085.      * flag that indicates that the options have been initialized.
  8086.      */
  8087.     if (should_copy)
  8088.         buf->b_p_initialized = TRUE;
  8089.     }
  8090.  
  8091.     check_buf_options(buf);        /* make sure we don't have NULLs */
  8092.     if (did_isk)
  8093.     (void)buf_init_chartab(buf, FALSE);
  8094. }
  8095.  
  8096. /*
  8097.  * Reset the 'modifiable' option and its default value.
  8098.  */
  8099.     void
  8100. reset_modifiable()
  8101. {
  8102.     int        opt_idx;
  8103.  
  8104.     curbuf->b_p_ma = FALSE;
  8105.     p_ma = FALSE;
  8106.     opt_idx = findoption((char_u *)"ma");
  8107.     options[opt_idx].def_val[VI_DEFAULT] = FALSE;
  8108. }
  8109.  
  8110. /*
  8111.  * Set the global value for 'iminsert' to the local value.
  8112.  */
  8113.     void
  8114. set_iminsert_global()
  8115. {
  8116.     p_iminsert = curbuf->b_p_iminsert;
  8117. }
  8118.  
  8119. /*
  8120.  * Set the global value for 'imsearch' to the local value.
  8121.  */
  8122.     void
  8123. set_imsearch_global()
  8124. {
  8125.     p_imsearch = curbuf->b_p_imsearch;
  8126. }
  8127.  
  8128. #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
  8129. static int expand_option_idx = -1;
  8130. static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
  8131. static int expand_option_flags = 0;
  8132.  
  8133.     void
  8134. set_context_in_set_cmd(xp, arg, opt_flags)
  8135.     expand_T    *xp;
  8136.     char_u    *arg;
  8137.     int        opt_flags;    /* OPT_GLOBAL and/or OPT_LOCAL */
  8138. {
  8139.     int        nextchar;
  8140.     long_u    flags = 0;    /* init for GCC */
  8141.     int        opt_idx = 0;    /* init for GCC */
  8142.     char_u    *p;
  8143.     char_u    *s;
  8144.     int        is_term_option = FALSE;
  8145.     int        key;
  8146.  
  8147.     expand_option_flags = opt_flags;
  8148.  
  8149.     xp->xp_context = EXPAND_SETTINGS;
  8150.     if (*arg == NUL)
  8151.     {
  8152.     xp->xp_pattern = arg;
  8153.     return;
  8154.     }
  8155.     p = arg + STRLEN(arg) - 1;
  8156.     if (*p == ' ' && *(p - 1) != '\\')
  8157.     {
  8158.     xp->xp_pattern = p + 1;
  8159.     return;
  8160.     }
  8161.     while (p > arg)
  8162.     {
  8163.     s = p;
  8164.     /* count number of backslashes before ' ' or ',' */
  8165.     if (*p == ' ' || *p == ',')
  8166.     {
  8167.         while (s > arg && *(s - 1) == '\\')
  8168.         --s;
  8169.     }
  8170.     /* break at a space with an even number of backslashes */
  8171.     if (*p == ' ' && ((p - s) & 1) == 0)
  8172.     {
  8173.         ++p;
  8174.         break;
  8175.     }
  8176.     --p;
  8177.     }
  8178.     if (STRNCMP(p, "no", 2) == 0)
  8179.     {
  8180.     xp->xp_context = EXPAND_BOOL_SETTINGS;
  8181.     p += 2;
  8182.     }
  8183.     if (STRNCMP(p, "inv", 3) == 0)
  8184.     {
  8185.     xp->xp_context = EXPAND_BOOL_SETTINGS;
  8186.     p += 3;
  8187.     }
  8188.     xp->xp_pattern = arg = p;
  8189.     if (*arg == '<')
  8190.     {
  8191.     while (*p != '>')
  8192.         if (*p++ == NUL)        /* expand terminal option name */
  8193.         return;
  8194.     key = get_special_key_code(arg + 1);
  8195.     if (key == 0)            /* unknown name */
  8196.     {
  8197.         xp->xp_context = EXPAND_NOTHING;
  8198.         return;
  8199.     }
  8200.     nextchar = *++p;
  8201.     is_term_option = TRUE;
  8202.     expand_option_name[2] = KEY2TERMCAP0(key);
  8203.     expand_option_name[3] = KEY2TERMCAP1(key);
  8204.     }
  8205.     else
  8206.     {
  8207.     if (p[0] == 't' && p[1] == '_')
  8208.     {
  8209.         p += 2;
  8210.         if (*p != NUL)
  8211.         ++p;
  8212.         if (*p == NUL)
  8213.         return;        /* expand option name */
  8214.         nextchar = *++p;
  8215.         is_term_option = TRUE;
  8216.         expand_option_name[2] = p[-2];
  8217.         expand_option_name[3] = p[-1];
  8218.     }
  8219.     else
  8220.     {
  8221.         /* Allow * wildcard */
  8222.         while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
  8223.         p++;
  8224.         if (*p == NUL)
  8225.         return;
  8226.         nextchar = *p;
  8227.         *p = NUL;
  8228.         opt_idx = findoption(arg);
  8229.         *p = nextchar;
  8230.         if (opt_idx == -1 || options[opt_idx].var == NULL)
  8231.         {
  8232.         xp->xp_context = EXPAND_NOTHING;
  8233.         return;
  8234.         }
  8235.         flags = options[opt_idx].flags;
  8236.         if (flags & P_BOOL)
  8237.         {
  8238.         xp->xp_context = EXPAND_NOTHING;
  8239.         return;
  8240.         }
  8241.     }
  8242.     }
  8243.     /* handle "-=" and "+=" */
  8244.     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
  8245.     {
  8246.     ++p;
  8247.     nextchar = '=';
  8248.     }
  8249.     if ((nextchar != '=' && nextchar != ':')
  8250.                     || xp->xp_context == EXPAND_BOOL_SETTINGS)
  8251.     {
  8252.     xp->xp_context = EXPAND_UNSUCCESSFUL;
  8253.     return;
  8254.     }
  8255.     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
  8256.     {
  8257.     xp->xp_context = EXPAND_OLD_SETTING;
  8258.     if (is_term_option)
  8259.         expand_option_idx = -1;
  8260.     else
  8261.         expand_option_idx = opt_idx;
  8262.     xp->xp_pattern = p + 1;
  8263.     return;
  8264.     }
  8265.     xp->xp_context = EXPAND_NOTHING;
  8266.     if (is_term_option || (flags & P_NUM))
  8267.     return;
  8268.  
  8269.     xp->xp_pattern = p + 1;
  8270.  
  8271.     if (flags & P_EXPAND)
  8272.     {
  8273.     p = options[opt_idx].var;
  8274.     if (p == (char_u *)&p_bdir
  8275.         || p == (char_u *)&p_dir
  8276.         || p == (char_u *)&p_path
  8277.         || p == (char_u *)&p_rtp
  8278. #ifdef FEAT_SEARCHPATH
  8279.         || p == (char_u *)&p_cdpath
  8280. #endif
  8281. #ifdef FEAT_SESSION
  8282.         || p == (char_u *)&p_vdir
  8283. #endif
  8284.         )
  8285.     {
  8286.         xp->xp_context = EXPAND_DIRECTORIES;
  8287.         if (p == (char_u *)&p_path
  8288. #ifdef FEAT_SEARCHPATH
  8289.             || p == (char_u *)&p_cdpath
  8290. #endif
  8291.            )
  8292.         xp->xp_backslash = XP_BS_THREE;
  8293.         else
  8294.         xp->xp_backslash = XP_BS_ONE;
  8295.     }
  8296.     else
  8297.     {
  8298.         xp->xp_context = EXPAND_FILES;
  8299.         /* for 'tags' need three backslashes for a space */
  8300.         if (p == (char_u *)&p_tags)
  8301.         xp->xp_backslash = XP_BS_THREE;
  8302.         else
  8303.         xp->xp_backslash = XP_BS_ONE;
  8304.     }
  8305.     }
  8306.  
  8307.     /* For an option that is a list of file names, find the start of the
  8308.      * last file name. */
  8309.     for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
  8310.     {
  8311.     /* count number of backslashes before ' ' or ',' */
  8312.     if (*p == ' ' || *p == ',')
  8313.     {
  8314.         s = p;
  8315.         while (s > xp->xp_pattern && *(s - 1) == '\\')
  8316.         --s;
  8317.         if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
  8318.             || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
  8319.         {
  8320.         xp->xp_pattern = p + 1;
  8321.         break;
  8322.         }
  8323.     }
  8324.     }
  8325.  
  8326.     return;
  8327. }
  8328.  
  8329.     int
  8330. ExpandSettings(xp, regmatch, num_file, file)
  8331.     expand_T    *xp;
  8332.     regmatch_T    *regmatch;
  8333.     int        *num_file;
  8334.     char_u    ***file;
  8335. {
  8336.     int        num_normal = 0;        /* Nr of matching non-term-code settings */
  8337.     int        num_term = 0;        /* Nr of matching terminal code settings */
  8338.     int        opt_idx;
  8339.     int        match;
  8340.     int        count = 0;
  8341.     char_u    *str;
  8342.     int        loop;
  8343.     int        is_term_opt;
  8344.     char_u    name_buf[MAX_KEY_NAME_LEN];
  8345.     static char *(names[]) = {"all", "termcap"};
  8346.     int        ic = regmatch->rm_ic;    /* remember the ignore-case flag */
  8347.  
  8348.     /* do this loop twice:
  8349.      * loop == 0: count the number of matching options
  8350.      * loop == 1: copy the matching options into allocated memory
  8351.      */
  8352.     for (loop = 0; loop <= 1; ++loop)
  8353.     {
  8354.     regmatch->rm_ic = ic;
  8355.     if (xp->xp_context != EXPAND_BOOL_SETTINGS)
  8356.     {
  8357.         for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
  8358.         if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
  8359.         {
  8360.             if (loop == 0)
  8361.             num_normal++;
  8362.             else
  8363.             (*file)[count++] = vim_strsave((char_u *)names[match]);
  8364.         }
  8365.     }
  8366.     for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
  8367.                                     opt_idx++)
  8368.     {
  8369.         if (options[opt_idx].var == NULL)
  8370.         continue;
  8371.         if (xp->xp_context == EXPAND_BOOL_SETTINGS
  8372.           && !(options[opt_idx].flags & P_BOOL))
  8373.         continue;
  8374.         is_term_opt = istermoption(&options[opt_idx]);
  8375.         if (is_term_opt && num_normal > 0)
  8376.         continue;
  8377.         match = FALSE;
  8378.         if (vim_regexec(regmatch, str, (colnr_T)0)
  8379.             || (options[opt_idx].shortname != NULL
  8380.             && vim_regexec(regmatch,
  8381.                (char_u *)options[opt_idx].shortname, (colnr_T)0)))
  8382.         match = TRUE;
  8383.         else if (is_term_opt)
  8384.         {
  8385.         name_buf[0] = '<';
  8386.         name_buf[1] = 't';
  8387.         name_buf[2] = '_';
  8388.         name_buf[3] = str[2];
  8389.         name_buf[4] = str[3];
  8390.         name_buf[5] = '>';
  8391.         name_buf[6] = NUL;
  8392.         if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  8393.         {
  8394.             match = TRUE;
  8395.             str = name_buf;
  8396.         }
  8397.         }
  8398.         if (match)
  8399.         {
  8400.         if (loop == 0)
  8401.         {
  8402.             if (is_term_opt)
  8403.             num_term++;
  8404.             else
  8405.             num_normal++;
  8406.         }
  8407.         else
  8408.             (*file)[count++] = vim_strsave(str);
  8409.         }
  8410.     }
  8411.     /*
  8412.      * Check terminal key codes, these are not in the option table
  8413.      */
  8414.     if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
  8415.     {
  8416.         for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
  8417.         {
  8418.         if (!isprint(str[0]) || !isprint(str[1]))
  8419.             continue;
  8420.  
  8421.         name_buf[0] = 't';
  8422.         name_buf[1] = '_';
  8423.         name_buf[2] = str[0];
  8424.         name_buf[3] = str[1];
  8425.         name_buf[4] = NUL;
  8426.  
  8427.         match = FALSE;
  8428.         if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  8429.             match = TRUE;
  8430.         else
  8431.         {
  8432.             name_buf[0] = '<';
  8433.             name_buf[1] = 't';
  8434.             name_buf[2] = '_';
  8435.             name_buf[3] = str[0];
  8436.             name_buf[4] = str[1];
  8437.             name_buf[5] = '>';
  8438.             name_buf[6] = NUL;
  8439.  
  8440.             if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  8441.             match = TRUE;
  8442.         }
  8443.         if (match)
  8444.         {
  8445.             if (loop == 0)
  8446.             num_term++;
  8447.             else
  8448.             (*file)[count++] = vim_strsave(name_buf);
  8449.         }
  8450.         }
  8451.  
  8452.         /*
  8453.          * Check special key names.
  8454.          */
  8455.         regmatch->rm_ic = TRUE;        /* ignore case here */
  8456.         for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
  8457.         {
  8458.         name_buf[0] = '<';
  8459.         STRCPY(name_buf + 1, str);
  8460.         STRCAT(name_buf, ">");
  8461.  
  8462.         if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  8463.         {
  8464.             if (loop == 0)
  8465.             num_term++;
  8466.             else
  8467.             (*file)[count++] = vim_strsave(name_buf);
  8468.         }
  8469.         }
  8470.     }
  8471.     if (loop == 0)
  8472.     {
  8473.         if (num_normal > 0)
  8474.         *num_file = num_normal;
  8475.         else if (num_term > 0)
  8476.         *num_file = num_term;
  8477.         else
  8478.         return OK;
  8479.         *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
  8480.         if (*file == NULL)
  8481.         {
  8482.         *file = (char_u **)"";
  8483.         return FAIL;
  8484.         }
  8485.     }
  8486.     }
  8487.     return OK;
  8488. }
  8489.  
  8490.     int
  8491. ExpandOldSetting(num_file, file)
  8492.     int        *num_file;
  8493.     char_u  ***file;
  8494. {
  8495.     char_u  *var = NULL;    /* init for GCC */
  8496.     char_u  *buf;
  8497.  
  8498.     *num_file = 0;
  8499.     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
  8500.     if (*file == NULL)
  8501.     return FAIL;
  8502.  
  8503.     /*
  8504.      * For a terminal key code expand_option_idx is < 0.
  8505.      */
  8506.     if (expand_option_idx < 0)
  8507.     {
  8508.     var = find_termcode(expand_option_name + 2);
  8509.     if (var == NULL)
  8510.         expand_option_idx = findoption(expand_option_name);
  8511.     }
  8512.  
  8513.     if (expand_option_idx >= 0)
  8514.     {
  8515.     /* put string of option value in NameBuff */
  8516.     option_value2string(&options[expand_option_idx], expand_option_flags);
  8517.     var = NameBuff;
  8518.     }
  8519.     else if (var == NULL)
  8520.     var = (char_u *)"";
  8521.  
  8522.     /* A backslash is required before some characters.  This is the reverse of
  8523.      * what happens in do_set(). */
  8524.     buf = vim_strsave_escaped(var, escape_chars);
  8525.  
  8526.     if (buf == NULL)
  8527.     {
  8528.     vim_free(*file);
  8529.     *file = NULL;
  8530.     return FAIL;
  8531.     }
  8532.  
  8533. #ifdef BACKSLASH_IN_FILENAME
  8534.     /* For MS-Windows et al. we don't double backslashes at the start and
  8535.      * before a file name character. */
  8536.     for (var = buf; *var != NUL; )
  8537.     {
  8538.     if (var[0] == '\\' && var[1] == '\\'
  8539.         && expand_option_idx >= 0
  8540.         && (options[expand_option_idx].flags & P_EXPAND)
  8541.         && vim_isfilec(var[2])
  8542.         && (var[2] != '\\' || (var == buf && var[4] != '\\')))
  8543.         mch_memmove(var, var + 1, STRLEN(var));
  8544. #ifdef FEAT_MBYTE
  8545.     else if (has_mbyte)
  8546.         var += (*mb_ptr2len_check)(var) - 1;
  8547. #endif
  8548.     ++var;
  8549.     }
  8550. #endif
  8551.  
  8552.     *file[0] = buf;
  8553.     *num_file = 1;
  8554.     return OK;
  8555. }
  8556. #endif
  8557.  
  8558. /*
  8559.  * Get the value for the numeric or string option *opp in a nice format into
  8560.  * NameBuff[].  Must not be called with a hidden option!
  8561.  */
  8562.     static void
  8563. option_value2string(opp, opt_flags)
  8564.     struct vimoption    *opp;
  8565.     int            opt_flags;    /* OPT_GLOBAL and/or OPT_LOCAL */
  8566. {
  8567.     char_u    *varp;
  8568.  
  8569.     varp = get_varp_scope(opp, opt_flags);
  8570.  
  8571.     if (opp->flags & P_NUM)
  8572.     {
  8573.     long wc = 0;
  8574.  
  8575.     if (wc_use_keyname(varp, &wc))
  8576.         STRCPY(NameBuff, get_special_key_name((int)wc, 0));
  8577.     else if (wc != 0)
  8578.         STRCPY(NameBuff, transchar((int)wc));
  8579.     else
  8580.         sprintf((char *)NameBuff, "%ld", *(long *)varp);
  8581.     }
  8582.     else    /* P_STRING */
  8583.     {
  8584.     varp = *(char_u **)(varp);
  8585.     if (varp == NULL)            /* just in case */
  8586.         NameBuff[0] = NUL;
  8587. #ifdef FEAT_CRYPT
  8588.     /* don't show the actual value of 'key', only that it's set */
  8589.     if (opp->var == (char_u *)&p_key && *varp)
  8590.         STRCPY(NameBuff, "*****");
  8591. #endif
  8592.     else if (opp->flags & P_EXPAND)
  8593.         home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
  8594.     /* Translate 'pastetoggle' into special key names */
  8595.     else if ((char_u **)opp->var == &p_pt)
  8596.         str2specialbuf(p_pt, NameBuff, MAXPATHL);
  8597.     else
  8598.         STRNCPY(NameBuff, varp, MAXPATHL);
  8599.     }
  8600. }
  8601.  
  8602. /*
  8603.  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
  8604.  * printed as a keyname.
  8605.  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
  8606.  */
  8607.     static int
  8608. wc_use_keyname(varp, wcp)
  8609.     char_u    *varp;
  8610.     long    *wcp;
  8611. {
  8612.     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
  8613.     {
  8614.     *wcp = *(long *)varp;
  8615.     if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
  8616.         return TRUE;
  8617.     }
  8618.     return FALSE;
  8619. }
  8620.  
  8621. #ifdef FEAT_LANGMAP
  8622. /*
  8623.  * Any character has an equivalent character.  This is used for keyboards that
  8624.  * have a special language mode that sends characters above 128 (although
  8625.  * other characters can be translated too).
  8626.  */
  8627.  
  8628. /*
  8629.  * char_u langmap_mapchar[256];
  8630.  * Normally maps each of the 128 upper chars to an <128 ascii char; used to
  8631.  * "translate" native lang chars in normal mode or some cases of
  8632.  * insert mode without having to tediously switch lang mode back&forth.
  8633.  */
  8634.  
  8635.     static void
  8636. langmap_init()
  8637. {
  8638.     int i;
  8639.  
  8640.     for (i = 0; i < 256; i++)        /* we init with a-one-to one map */
  8641.     langmap_mapchar[i] = i;
  8642. }
  8643.  
  8644. /*
  8645.  * Called when langmap option is set; the language map can be
  8646.  * changed at any time!
  8647.  */
  8648.     static void
  8649. langmap_set()
  8650. {
  8651.     char_u  *p;
  8652.     char_u  *p2;
  8653.     int        from, to;
  8654.  
  8655.     langmap_init();                /* back to one-to-one map first */
  8656.  
  8657.     for (p = p_langmap; p[0] != NUL; )
  8658.     {
  8659.     for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; ++p2)
  8660.     {
  8661.         if (p2[0] == '\\' && p2[1] != NUL)
  8662.         ++p2;
  8663. #ifdef FEAT_MBYTE
  8664.         p2 += (*mb_ptr2len_check)(p2) - 1;
  8665. #endif
  8666.     }
  8667.     if (p2[0] == ';')
  8668.         ++p2;        /* abcd;ABCD form, p2 points to A */
  8669.     else
  8670.         p2 = NULL;        /* aAbBcCdD form, p2 is NULL */
  8671.     while (p[0])
  8672.     {
  8673.         if (p[0] == '\\' && p[1] != NUL)
  8674.         ++p;
  8675. #ifdef FEAT_MBYTE
  8676.         from = (*mb_ptr2char)(p);
  8677. #else
  8678.         from = p[0];
  8679. #endif
  8680.         if (p2 == NULL)
  8681.         {
  8682. #ifdef FEAT_MBYTE
  8683.         p += (*mb_ptr2len_check)(p);
  8684. #else
  8685.         ++p;
  8686. #endif
  8687.         if (p[0] == '\\')
  8688.             ++p;
  8689. #ifdef FEAT_MBYTE
  8690.         to = (*mb_ptr2char)(p);
  8691. #else
  8692.         to = p[0];
  8693. #endif
  8694.         }
  8695.         else
  8696.         {
  8697.         if (p2[0] == '\\')
  8698.             ++p2;
  8699. #ifdef FEAT_MBYTE
  8700.         to = (*mb_ptr2char)(p2);
  8701. #else
  8702.         to = p2[0];
  8703. #endif
  8704.         }
  8705.         if (to == NUL)
  8706.         {
  8707.         EMSG2(_("E357: 'langmap': Matching character missing for %s"),
  8708.                                  transchar(from));
  8709.         return;
  8710.         }
  8711.         langmap_mapchar[from & 255] = to;
  8712.  
  8713.         /* Advance to next pair */
  8714. #ifdef FEAT_MBYTE
  8715.         p += (*mb_ptr2len_check)(p);
  8716. #else
  8717.         ++p;
  8718. #endif
  8719.         if (p2 == NULL)
  8720.         {
  8721.         if (p[0] == ',')
  8722.         {
  8723.             ++p;
  8724.             break;
  8725.         }
  8726.         }
  8727.         else
  8728.         {
  8729. #ifdef FEAT_MBYTE
  8730.         p2 += (*mb_ptr2len_check)(p2);
  8731. #else
  8732.         ++p2;
  8733. #endif
  8734.         if (*p == ';')
  8735.         {
  8736.             p = p2;
  8737.             if (p[0] != NUL)
  8738.             {
  8739.             if (p[0] != ',')
  8740.             {
  8741.                 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
  8742.                 return;
  8743.             }
  8744.             ++p;
  8745.             }
  8746.             break;
  8747.         }
  8748.         }
  8749.     }
  8750.     }
  8751. }
  8752. #endif
  8753.  
  8754. /*
  8755.  * Return TRUE if format option 'x' is in effect.
  8756.  * Take care of no formatting when 'paste' is set.
  8757.  */
  8758.     int
  8759. has_format_option(x)
  8760.     int        x;
  8761. {
  8762.     if (p_paste)
  8763.     return FALSE;
  8764.     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
  8765. }
  8766.  
  8767. /*
  8768.  * Return TRUE if "x" is present in 'shortmess' option, or
  8769.  * 'shortmess' contains 'a' and "x" is present in SHM_A.
  8770.  */
  8771.     int
  8772. shortmess(x)
  8773.     int        x;
  8774. {
  8775.     return (   vim_strchr(p_shm, x) != NULL
  8776.         || (vim_strchr(p_shm, 'a') != NULL
  8777.         && vim_strchr((char_u *)SHM_A, x) != NULL));
  8778. }
  8779.  
  8780. /*
  8781.  * paste_option_changed() - Called after p_paste was set or reset.
  8782.  */
  8783.     static void
  8784. paste_option_changed()
  8785. {
  8786.     static int    old_p_paste = FALSE;
  8787.     static int    save_sm = 0;
  8788. #ifdef FEAT_CMDL_INFO
  8789.     static int    save_ru = 0;
  8790. #endif
  8791. #ifdef FEAT_RIGHTLEFT
  8792.     static int    save_ri = 0;
  8793.     static int    save_hkmap = 0;
  8794. #endif
  8795.     buf_T    *buf;
  8796.  
  8797.     if (p_paste)
  8798.     {
  8799.     /*
  8800.      * Paste switched from off to on.
  8801.      * Save the current values, so they can be restored later.
  8802.      */
  8803.     if (!old_p_paste)
  8804.     {
  8805.         /* save options for each buffer */
  8806.         for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  8807.         {
  8808.         buf->b_p_tw_nopaste = buf->b_p_tw;
  8809.         buf->b_p_wm_nopaste = buf->b_p_wm;
  8810.         buf->b_p_sts_nopaste = buf->b_p_sts;
  8811.         buf->b_p_ai_nopaste = buf->b_p_ai;
  8812.         }
  8813.  
  8814.         /* save global options */
  8815.         save_sm = p_sm;
  8816. #ifdef FEAT_CMDL_INFO
  8817.         save_ru = p_ru;
  8818. #endif
  8819. #ifdef FEAT_RIGHTLEFT
  8820.         save_ri = p_ri;
  8821.         save_hkmap = p_hkmap;
  8822. #endif
  8823.         /* save global values for local buffer options */
  8824.         p_tw_nopaste = p_tw;
  8825.         p_wm_nopaste = p_wm;
  8826.         p_sts_nopaste = p_sts;
  8827.         p_ai_nopaste = p_ai;
  8828.     }
  8829.  
  8830.     /*
  8831.      * Always set the option values, also when 'paste' is set when it is
  8832.      * already on.
  8833.      */
  8834.     /* set options for each buffer */
  8835.     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  8836.     {
  8837.         buf->b_p_tw = 0;        /* textwidth is 0 */
  8838.         buf->b_p_wm = 0;        /* wrapmargin is 0 */
  8839.         buf->b_p_sts = 0;        /* softtabstop is 0 */
  8840.         buf->b_p_ai = 0;        /* no auto-indent */
  8841.     }
  8842.  
  8843.     /* set global options */
  8844.     p_sm = 0;            /* no showmatch */
  8845. #ifdef FEAT_CMDL_INFO
  8846. # ifdef FEAT_WINDOWS
  8847.     if (p_ru)
  8848.         status_redraw_all();    /* redraw to remove the ruler */
  8849. # endif
  8850.     p_ru = 0;            /* no ruler */
  8851. #endif
  8852. #ifdef FEAT_RIGHTLEFT
  8853.     p_ri = 0;            /* no reverse insert */
  8854.     p_hkmap = 0;            /* no Hebrew keyboard */
  8855. #endif
  8856.     /* set global values for local buffer options */
  8857.     p_tw = 0;
  8858.     p_wm = 0;
  8859.     p_sts = 0;
  8860.     p_ai = 0;
  8861.     }
  8862.  
  8863.     /*
  8864.      * Paste switched from on to off: Restore saved values.
  8865.      */
  8866.     else if (old_p_paste)
  8867.     {
  8868.     /* restore options for each buffer */
  8869.     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  8870.     {
  8871.         buf->b_p_tw = buf->b_p_tw_nopaste;
  8872.         buf->b_p_wm = buf->b_p_wm_nopaste;
  8873.         buf->b_p_sts = buf->b_p_sts_nopaste;
  8874.         buf->b_p_ai = buf->b_p_ai_nopaste;
  8875.     }
  8876.  
  8877.     /* restore global options */
  8878.     p_sm = save_sm;
  8879. #ifdef FEAT_CMDL_INFO
  8880. # ifdef FEAT_WINDOWS
  8881.     if (p_ru != save_ru)
  8882.         status_redraw_all();    /* redraw to draw the ruler */
  8883. # endif
  8884.     p_ru = save_ru;
  8885. #endif
  8886. #ifdef FEAT_RIGHTLEFT
  8887.     p_ri = save_ri;
  8888.     p_hkmap = save_hkmap;
  8889. #endif
  8890.     /* set global values for local buffer options */
  8891.     p_tw = p_tw_nopaste;
  8892.     p_wm = p_wm_nopaste;
  8893.     p_sts = p_sts_nopaste;
  8894.     p_ai = p_ai_nopaste;
  8895.     }
  8896.  
  8897.     old_p_paste = p_paste;
  8898. }
  8899.  
  8900. /*
  8901.  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
  8902.  *
  8903.  * Reset 'compatible' and set the values for options that didn't get set yet
  8904.  * to the Vim defaults.
  8905.  * Don't do this if the 'compatible' option has been set or reset before.
  8906.  */
  8907.     void
  8908. vimrc_found()
  8909. {
  8910.     int        opt_idx;
  8911.  
  8912.     if (!option_was_set((char_u *)"cp"))
  8913.     {
  8914.     p_cp = FALSE;
  8915.     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
  8916.         if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
  8917.         set_option_default(opt_idx, OPT_FREE, FALSE);
  8918.     didset_options();
  8919.     }
  8920. }
  8921.  
  8922. /*
  8923.  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
  8924.  */
  8925.     void
  8926. change_compatible(on)
  8927.     int        on;
  8928. {
  8929.     if (p_cp != on)
  8930.     {
  8931.     p_cp = on;
  8932.     compatible_set();
  8933.     }
  8934.     options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
  8935. }
  8936.  
  8937. /*
  8938.  * Return TRUE when option "name" has been set.
  8939.  */
  8940.     int
  8941. option_was_set(name)
  8942.     char_u    *name;
  8943. {
  8944.     int idx;
  8945.  
  8946.     idx = findoption(name);
  8947.     if (idx < 0)    /* unknown option */
  8948.     return FALSE;
  8949.     if (options[idx].flags & P_WAS_SET)
  8950.     return TRUE;
  8951.     return FALSE;
  8952. }
  8953.  
  8954. /*
  8955.  * compatible_set() - Called when 'compatible' has been set or unset.
  8956.  *
  8957.  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
  8958.  * flag) to a Vi compatible value.
  8959.  * When 'compatible' is unset: Set all options that have a different default
  8960.  * for Vim (without the P_VI_DEF flag) to that default.
  8961.  */
  8962.     static void
  8963. compatible_set()
  8964. {
  8965.     int        opt_idx;
  8966.  
  8967.     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
  8968.     if (       ((options[opt_idx].flags & P_VIM) && p_cp)
  8969.         || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
  8970.         set_option_default(opt_idx, OPT_FREE, p_cp);
  8971.     didset_options();
  8972. }
  8973.  
  8974. #ifdef FEAT_LINEBREAK
  8975.  
  8976. # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
  8977.    /* Borland C++ screws up loop optimisation here (negri) */
  8978. #  pragma option -O-l
  8979. # endif
  8980.  
  8981. /*
  8982.  * fill_breakat_flags() -- called when 'breakat' changes value.
  8983.  */
  8984.     static void
  8985. fill_breakat_flags()
  8986. {
  8987.     char_u    *c;
  8988.     int        i;
  8989.  
  8990.     for (i = 0; i < 256; i++)
  8991.     breakat_flags[i] = FALSE;
  8992.  
  8993.     if (p_breakat != NULL)
  8994.     for (c = p_breakat; *c; c++)
  8995.         breakat_flags[*c] = TRUE;
  8996. }
  8997.  
  8998. # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
  8999. #  pragma option -O.l
  9000. # endif
  9001.  
  9002. #endif
  9003.  
  9004. /*
  9005.  * Check an option that can be a range of string values.
  9006.  *
  9007.  * Return OK for correct value, FAIL otherwise.
  9008.  * Empty is always OK.
  9009.  */
  9010.     static int
  9011. check_opt_strings(val, values, list)
  9012.     char_u    *val;
  9013.     char    **values;
  9014.     int        list;        /* when TRUE: accept a list of values */
  9015. {
  9016.     return opt_strings_flags(val, values, NULL, list);
  9017. }
  9018.  
  9019. /*
  9020.  * Handle an option that can be a range of string values.
  9021.  * Set a flag in "*flagp" for each string present.
  9022.  *
  9023.  * Return OK for correct value, FAIL otherwise.
  9024.  * Empty is always OK.
  9025.  */
  9026.     static int
  9027. opt_strings_flags(val, values, flagp, list)
  9028.     char_u    *val;        /* new value */
  9029.     char    **values;    /* array of valid string values */
  9030.     unsigned    *flagp;
  9031.     int        list;        /* when TRUE: accept a list of values */
  9032. {
  9033.     int        i;
  9034.     int        len;
  9035.     unsigned    new_flags = 0;
  9036.  
  9037.     while (*val)
  9038.     {
  9039.     for (i = 0; ; ++i)
  9040.     {
  9041.         if (values[i] == NULL)    /* val not found in values[] */
  9042.         return FAIL;
  9043.  
  9044.         len = (int)STRLEN(values[i]);
  9045.         if (STRNCMP(values[i], val, len) == 0
  9046.             && ((list && val[len] == ',') || val[len] == NUL))
  9047.         {
  9048.         val += len + (val[len] == ',');
  9049.         new_flags |= (1 << i);
  9050.         break;        /* check next item in val list */
  9051.         }
  9052.     }
  9053.     }
  9054.     if (flagp != NULL)
  9055.     *flagp = new_flags;
  9056.  
  9057.     return OK;
  9058. }
  9059.  
  9060. /*
  9061.  * Read the 'wildmode' option, fill wim_flags[].
  9062.  */
  9063.     static int
  9064. check_opt_wim()
  9065. {
  9066.     char_u    new_wim_flags[4];
  9067.     char_u    *p;
  9068.     int        i;
  9069.     int        idx = 0;
  9070.  
  9071.     for (i = 0; i < 4; ++i)
  9072.     new_wim_flags[i] = 0;
  9073.  
  9074.     for (p = p_wim; *p; ++p)
  9075.     {
  9076.     for (i = 0; ASCII_ISALPHA(p[i]); ++i)
  9077.         ;
  9078.     if (p[i] != NUL && p[i] != ',' && p[i] != ':')
  9079.         return FAIL;
  9080.     if (i == 7 && STRNCMP(p, "longest", 7) == 0)
  9081.         new_wim_flags[idx] |= WIM_LONGEST;
  9082.     else if (i == 4 && STRNCMP(p, "full", 4) == 0)
  9083.         new_wim_flags[idx] |= WIM_FULL;
  9084.     else if (i == 4 && STRNCMP(p, "list", 4) == 0)
  9085.         new_wim_flags[idx] |= WIM_LIST;
  9086.     else
  9087.         return FAIL;
  9088.     p += i;
  9089.     if (*p == NUL)
  9090.         break;
  9091.     if (*p == ',')
  9092.     {
  9093.         if (idx == 3)
  9094.         return FAIL;
  9095.         ++idx;
  9096.     }
  9097.     }
  9098.  
  9099.     /* fill remaining entries with last flag */
  9100.     while (idx < 3)
  9101.     {
  9102.     new_wim_flags[idx + 1] = new_wim_flags[idx];
  9103.     ++idx;
  9104.     }
  9105.  
  9106.     /* only when there are no errors, wim_flags[] is changed */
  9107.     for (i = 0; i < 4; ++i)
  9108.     wim_flags[i] = new_wim_flags[i];
  9109.     return OK;
  9110. }
  9111.  
  9112. /*
  9113.  * Check if backspacing over something is allowed.
  9114.  */
  9115.     int
  9116. can_bs(what)
  9117.     int        what;        /* BS_INDENT, BS_EOL or BS_START */
  9118. {
  9119.     switch (*p_bs)
  9120.     {
  9121.     case '2':    return TRUE;
  9122.     case '1':    return (what != BS_START);
  9123.     case '0':    return FALSE;
  9124.     }
  9125.     return vim_strchr(p_bs, what) != NULL;
  9126. }
  9127.  
  9128. /*
  9129.  * Save the current values of 'fileformat' and 'fileencoding', so that we know
  9130.  * the file must be considered changed when the value is different.
  9131.  */
  9132.     void
  9133. save_file_ff(buf)
  9134.     buf_T    *buf;
  9135. {
  9136.     buf->b_start_ffc = *buf->b_p_ff;
  9137.     buf->b_start_eol = buf->b_p_eol;
  9138. #ifdef FEAT_MBYTE
  9139.     /* Only use free/alloc when necessary, they take time. */
  9140.     if (buf->b_start_fenc == NULL
  9141.                  || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
  9142.     {
  9143.     vim_free(buf->b_start_fenc);
  9144.     buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
  9145.     }
  9146. #endif
  9147. }
  9148.  
  9149. /*
  9150.  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
  9151.  * from when editing started (save_file_ff() called).
  9152.  * Also when 'endofline' was changed and 'binary' is set.
  9153.  */
  9154.     int
  9155. file_ff_differs(buf)
  9156.     buf_T    *buf;
  9157. {
  9158.     if (buf->b_start_ffc != *buf->b_p_ff)
  9159.     return TRUE;
  9160.     if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
  9161.     return TRUE;
  9162. #ifdef FEAT_MBYTE
  9163.     if (buf->b_start_fenc == NULL)
  9164.     return (*buf->b_p_fenc != NUL);
  9165.     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
  9166. #else
  9167.     return FALSE;
  9168. #endif
  9169. }
  9170.  
  9171. /*
  9172.  * return OK if "p" is a valid fileformat name, FAIL otherwise.
  9173.  */
  9174.     int
  9175. check_ff_value(p)
  9176.     char_u    *p;
  9177. {
  9178.     return check_opt_strings(p, p_ff_values, FALSE);
  9179. }
  9180.