annotate src/evalvars.c @ 18478:94223687df0e

Added tag v8.1.2233 for changeset e93cab5d0f0f27fad7882f1f412927df055b090d
author Bram Moolenaar <Bram@vim.org>
date Tue, 29 Oct 2019 04:30:05 +0100
parents e93cab5d0f0f
children e47b04b01793
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * evalvars.c: functions for dealing with variables
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 static char *e_letunexp = N_("E18: Unexpected characters in :let");
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
20 static dictitem_T globvars_var; // variable used for g:
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
21 static dict_T globvardict; // Dictionary with g: variables
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
22 #define globvarht globvardict.dv_hashtab
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
23
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
24 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
25 * Old Vim variables such as "v:version" are also available without the "v:".
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
26 * Also in functions. We need a special hashtable for them.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
27 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
28 static hashtab_T compat_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
29
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
30 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
31 * Array to hold the value of v: variables.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
32 * The value is in a dictitem, so that it can also be used in the v: scope.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
33 * The reason to use this table anyway is for very quick access to the
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
34 * variables with the VV_ defines.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
35 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
36
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
37 // values for vv_flags:
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
38 #define VV_COMPAT 1 // compatible, also used without "v:"
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
39 #define VV_RO 2 // read-only
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
40 #define VV_RO_SBX 4 // read-only in the sandbox
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
41
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
42 #define VV_NAME(s, t) s, {{t, 0, {0}}, 0, {0}}
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
43
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
44 static struct vimvar
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
45 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
46 char *vv_name; // name of variable, without v:
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
47 dictitem16_T vv_di; // value and name for key (max 16 chars!)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
48 char vv_flags; // VV_COMPAT, VV_RO, VV_RO_SBX
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
49 } vimvars[VV_LEN] =
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
50 {
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
51 // The order here must match the VV_ defines in vim.h!
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
52 // Initializing a union does not work, leave tv.vval empty to get zero's.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
53 {VV_NAME("count", VAR_NUMBER), VV_COMPAT+VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
54 {VV_NAME("count1", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
55 {VV_NAME("prevcount", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
56 {VV_NAME("errmsg", VAR_STRING), VV_COMPAT},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
57 {VV_NAME("warningmsg", VAR_STRING), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
58 {VV_NAME("statusmsg", VAR_STRING), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
59 {VV_NAME("shell_error", VAR_NUMBER), VV_COMPAT+VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
60 {VV_NAME("this_session", VAR_STRING), VV_COMPAT},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
61 {VV_NAME("version", VAR_NUMBER), VV_COMPAT+VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
62 {VV_NAME("lnum", VAR_NUMBER), VV_RO_SBX},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
63 {VV_NAME("termresponse", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
64 {VV_NAME("fname", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
65 {VV_NAME("lang", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
66 {VV_NAME("lc_time", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
67 {VV_NAME("ctype", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
68 {VV_NAME("charconvert_from", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
69 {VV_NAME("charconvert_to", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
70 {VV_NAME("fname_in", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
71 {VV_NAME("fname_out", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
72 {VV_NAME("fname_new", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
73 {VV_NAME("fname_diff", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
74 {VV_NAME("cmdarg", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
75 {VV_NAME("foldstart", VAR_NUMBER), VV_RO_SBX},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
76 {VV_NAME("foldend", VAR_NUMBER), VV_RO_SBX},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
77 {VV_NAME("folddashes", VAR_STRING), VV_RO_SBX},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
78 {VV_NAME("foldlevel", VAR_NUMBER), VV_RO_SBX},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
79 {VV_NAME("progname", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
80 {VV_NAME("servername", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
81 {VV_NAME("dying", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
82 {VV_NAME("exception", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
83 {VV_NAME("throwpoint", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
84 {VV_NAME("register", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
85 {VV_NAME("cmdbang", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
86 {VV_NAME("insertmode", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
87 {VV_NAME("val", VAR_UNKNOWN), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
88 {VV_NAME("key", VAR_UNKNOWN), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
89 {VV_NAME("profiling", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
90 {VV_NAME("fcs_reason", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
91 {VV_NAME("fcs_choice", VAR_STRING), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
92 {VV_NAME("beval_bufnr", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
93 {VV_NAME("beval_winnr", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
94 {VV_NAME("beval_winid", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
95 {VV_NAME("beval_lnum", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
96 {VV_NAME("beval_col", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
97 {VV_NAME("beval_text", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
98 {VV_NAME("scrollstart", VAR_STRING), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
99 {VV_NAME("swapname", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
100 {VV_NAME("swapchoice", VAR_STRING), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
101 {VV_NAME("swapcommand", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
102 {VV_NAME("char", VAR_STRING), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
103 {VV_NAME("mouse_win", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
104 {VV_NAME("mouse_winid", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
105 {VV_NAME("mouse_lnum", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
106 {VV_NAME("mouse_col", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
107 {VV_NAME("operator", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
108 {VV_NAME("searchforward", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
109 {VV_NAME("hlsearch", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
110 {VV_NAME("oldfiles", VAR_LIST), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
111 {VV_NAME("windowid", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
112 {VV_NAME("progpath", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
113 {VV_NAME("completed_item", VAR_DICT), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
114 {VV_NAME("option_new", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
115 {VV_NAME("option_old", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
116 {VV_NAME("option_oldlocal", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
117 {VV_NAME("option_oldglobal", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
118 {VV_NAME("option_command", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
119 {VV_NAME("option_type", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
120 {VV_NAME("errors", VAR_LIST), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
121 {VV_NAME("false", VAR_SPECIAL), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
122 {VV_NAME("true", VAR_SPECIAL), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
123 {VV_NAME("null", VAR_SPECIAL), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
124 {VV_NAME("none", VAR_SPECIAL), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
125 {VV_NAME("vim_did_enter", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
126 {VV_NAME("testing", VAR_NUMBER), 0},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
127 {VV_NAME("t_number", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
128 {VV_NAME("t_string", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
129 {VV_NAME("t_func", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
130 {VV_NAME("t_list", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
131 {VV_NAME("t_dict", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
132 {VV_NAME("t_float", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
133 {VV_NAME("t_bool", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
134 {VV_NAME("t_none", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
135 {VV_NAME("t_job", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
136 {VV_NAME("t_channel", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
137 {VV_NAME("t_blob", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
138 {VV_NAME("termrfgresp", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
139 {VV_NAME("termrbgresp", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
140 {VV_NAME("termu7resp", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
141 {VV_NAME("termstyleresp", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
142 {VV_NAME("termblinkresp", VAR_STRING), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
143 {VV_NAME("event", VAR_DICT), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
144 {VV_NAME("versionlong", VAR_NUMBER), VV_RO},
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
145 {VV_NAME("echospace", VAR_NUMBER), VV_RO},
18477
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
146 {VV_NAME("argv", VAR_LIST), VV_RO},
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
147 };
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
148
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
149 // shorthand
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
150 #define vv_type vv_di.di_tv.v_type
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
151 #define vv_nr vv_di.di_tv.vval.v_number
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
152 #define vv_float vv_di.di_tv.vval.v_float
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
153 #define vv_str vv_di.di_tv.vval.v_string
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
154 #define vv_list vv_di.di_tv.vval.v_list
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
155 #define vv_dict vv_di.di_tv.vval.v_dict
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
156 #define vv_blob vv_di.di_tv.vval.v_blob
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
157 #define vv_tv vv_di.di_tv
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
158
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
159 static dictitem_T vimvars_var; // variable used for v:
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
160 static dict_T vimvardict; // Dictionary with v: variables
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
161 #define vimvarht vimvardict.dv_hashtab
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
162
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
163 // for VIM_VERSION_ defines
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
164 #include "version.h"
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
165
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
166 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
167 * Array to hold the hashtab with variables local to each sourced script.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
168 * Each item holds a variable (nameless) that points to the dict_T.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
169 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
170 typedef struct
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
171 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
172 dictitem_T sv_var;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
173 dict_T sv_dict;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
174 } scriptvar_T;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
175
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
176 static garray_T ga_scripts = {0, 0, sizeof(scriptvar_T *), 4, NULL};
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
177 #define SCRIPT_SV(id) (((scriptvar_T **)ga_scripts.ga_data)[(id) - 1])
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
178 #define SCRIPT_VARS(id) (SCRIPT_SV(id)->sv_dict.dv_hashtab)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
179
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 static void ex_let_const(exarg_T *eap, int is_const);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 static char_u *skip_var_one(char_u *arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 static void list_glob_vars(int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 static void list_buf_vars(int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 static void list_win_vars(int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 static void list_tab_vars(int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int is_const, char_u *endchars, char_u *op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 static int do_unlet_var(lval_T *lp, char_u *name_end, int forceit);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 static void item_lock(typval_T *tv, int deep, int lock);
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
192 static void delete_var(hashtab_T *ht, hashitem_T *hi);
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 static void list_one_var(dictitem_T *v, char *prefix, int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 /*
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
197 * Initialize global and vim special variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
198 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
199 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
200 evalvars_init(void)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
201 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
202 int i;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
203 struct vimvar *p;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
204
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
205 init_var_dict(&globvardict, &globvars_var, VAR_DEF_SCOPE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
206 init_var_dict(&vimvardict, &vimvars_var, VAR_SCOPE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
207 vimvardict.dv_lock = VAR_FIXED;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
208 hash_init(&compat_hashtab);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
209
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
210 for (i = 0; i < VV_LEN; ++i)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
211 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
212 p = &vimvars[i];
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
213 if (STRLEN(p->vv_name) > DICTITEM16_KEY_LEN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
214 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
215 iemsg("INTERNAL: name too long, increase size of dictitem16_T");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
216 getout(1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
217 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
218 STRCPY(p->vv_di.di_key, p->vv_name);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
219 if (p->vv_flags & VV_RO)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
220 p->vv_di.di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
221 else if (p->vv_flags & VV_RO_SBX)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
222 p->vv_di.di_flags = DI_FLAGS_RO_SBX | DI_FLAGS_FIX;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
223 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
224 p->vv_di.di_flags = DI_FLAGS_FIX;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
225
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
226 // add to v: scope dict, unless the value is not always available
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
227 if (p->vv_type != VAR_UNKNOWN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
228 hash_add(&vimvarht, p->vv_di.di_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
229 if (p->vv_flags & VV_COMPAT)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
230 // add to compat scope dict
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
231 hash_add(&compat_hashtab, p->vv_di.di_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
232 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
233 vimvars[VV_VERSION].vv_nr = VIM_VERSION_100;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
234 vimvars[VV_VERSIONLONG].vv_nr = VIM_VERSION_100 * 10000 + highest_patch();
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
235
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
236 set_vim_var_nr(VV_SEARCHFORWARD, 1L);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
237 set_vim_var_nr(VV_HLSEARCH, 1L);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
238 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED));
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
239 set_vim_var_list(VV_ERRORS, list_alloc());
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
240 set_vim_var_dict(VV_EVENT, dict_alloc_lock(VAR_FIXED));
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
241
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
242 set_vim_var_nr(VV_FALSE, VVAL_FALSE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
243 set_vim_var_nr(VV_TRUE, VVAL_TRUE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
244 set_vim_var_nr(VV_NONE, VVAL_NONE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
245 set_vim_var_nr(VV_NULL, VVAL_NULL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
246
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
247 set_vim_var_nr(VV_TYPE_NUMBER, VAR_TYPE_NUMBER);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
248 set_vim_var_nr(VV_TYPE_STRING, VAR_TYPE_STRING);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
249 set_vim_var_nr(VV_TYPE_FUNC, VAR_TYPE_FUNC);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
250 set_vim_var_nr(VV_TYPE_LIST, VAR_TYPE_LIST);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
251 set_vim_var_nr(VV_TYPE_DICT, VAR_TYPE_DICT);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
252 set_vim_var_nr(VV_TYPE_FLOAT, VAR_TYPE_FLOAT);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
253 set_vim_var_nr(VV_TYPE_BOOL, VAR_TYPE_BOOL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
254 set_vim_var_nr(VV_TYPE_NONE, VAR_TYPE_NONE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
255 set_vim_var_nr(VV_TYPE_JOB, VAR_TYPE_JOB);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
256 set_vim_var_nr(VV_TYPE_CHANNEL, VAR_TYPE_CHANNEL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
257 set_vim_var_nr(VV_TYPE_BLOB, VAR_TYPE_BLOB);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
258
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
259 set_vim_var_nr(VV_ECHOSPACE, sc_col - 1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
260
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
261 set_reg_var(0); // default for v:register is not 0 but '"'
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
262 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
263
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
264 #if defined(EXITFREE) || defined(PROTO)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
265 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
266 * Free all vim variables information on exit
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
267 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
268 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
269 evalvars_clear(void)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
270 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
271 int i;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
272 struct vimvar *p;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
273
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
274 for (i = 0; i < VV_LEN; ++i)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
275 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
276 p = &vimvars[i];
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
277 if (p->vv_di.di_tv.v_type == VAR_STRING)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
278 VIM_CLEAR(p->vv_str);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
279 else if (p->vv_di.di_tv.v_type == VAR_LIST)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
280 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
281 list_unref(p->vv_list);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
282 p->vv_list = NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
283 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
284 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
285 hash_clear(&vimvarht);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
286 hash_init(&vimvarht); // garbage_collect() will access it
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
287 hash_clear(&compat_hashtab);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
288
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
289 // global variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
290 vars_clear(&globvarht);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
291
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
292 // Script-local variables. First clear all the variables and in a second
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
293 // loop free the scriptvar_T, because a variable in one script might hold
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
294 // a reference to the whole scope of another script.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
295 for (i = 1; i <= ga_scripts.ga_len; ++i)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
296 vars_clear(&SCRIPT_VARS(i));
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
297 for (i = 1; i <= ga_scripts.ga_len; ++i)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
298 vim_free(SCRIPT_SV(i));
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
299 ga_clear(&ga_scripts);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
300 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
301 #endif
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
302
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
303 int
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
304 garbage_collect_globvars(int copyID)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
305 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
306 return set_ref_in_ht(&globvarht, copyID, NULL);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
307 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
308
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
309 int
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
310 garbage_collect_vimvars(int copyID)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
311 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
312 return set_ref_in_ht(&vimvarht, copyID, NULL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
313 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
314
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
315 int
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
316 garbage_collect_scriptvars(int copyID)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
317 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
318 int i;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
319 int abort = FALSE;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
320
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
321 for (i = 1; i <= ga_scripts.ga_len; ++i)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
322 abort = abort || set_ref_in_ht(&SCRIPT_VARS(i), copyID, NULL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
323
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
324 return abort;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
325 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
326
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
327 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
328 * Set an internal variable to a string value. Creates the variable if it does
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
329 * not already exist.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
330 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
331 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
332 set_internal_string_var(char_u *name, char_u *value)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
333 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
334 char_u *val;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
335 typval_T *tvp;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
336
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
337 val = vim_strsave(value);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
338 if (val != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
339 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
340 tvp = alloc_string_tv(val);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
341 if (tvp != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
342 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
343 set_var(name, tvp, FALSE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
344 free_tv(tvp);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
345 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
346 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
347 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
348
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
349 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
350 eval_charconvert(
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
351 char_u *enc_from,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
352 char_u *enc_to,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
353 char_u *fname_from,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
354 char_u *fname_to)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
355 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
356 int err = FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
357
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
358 set_vim_var_string(VV_CC_FROM, enc_from, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
359 set_vim_var_string(VV_CC_TO, enc_to, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
360 set_vim_var_string(VV_FNAME_IN, fname_from, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
361 set_vim_var_string(VV_FNAME_OUT, fname_to, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
362 if (eval_to_bool(p_ccv, &err, NULL, FALSE))
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
363 err = TRUE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
364 set_vim_var_string(VV_CC_FROM, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
365 set_vim_var_string(VV_CC_TO, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
366 set_vim_var_string(VV_FNAME_IN, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
367 set_vim_var_string(VV_FNAME_OUT, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
368
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
369 if (err)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
370 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
371 return OK;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
372 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
373
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
374 # if defined(FEAT_POSTSCRIPT) || defined(PROTO)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
375 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
376 eval_printexpr(char_u *fname, char_u *args)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
377 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
378 int err = FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
379
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
380 set_vim_var_string(VV_FNAME_IN, fname, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
381 set_vim_var_string(VV_CMDARG, args, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
382 if (eval_to_bool(p_pexpr, &err, NULL, FALSE))
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
383 err = TRUE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
384 set_vim_var_string(VV_FNAME_IN, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
385 set_vim_var_string(VV_CMDARG, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
386
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
387 if (err)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
388 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
389 mch_remove(fname);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
390 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
391 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
392 return OK;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
393 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
394 # endif
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
395
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
396 # if defined(FEAT_DIFF) || defined(PROTO)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
397 void
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
398 eval_diff(
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
399 char_u *origfile,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
400 char_u *newfile,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
401 char_u *outfile)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
402 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
403 int err = FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
404
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
405 set_vim_var_string(VV_FNAME_IN, origfile, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
406 set_vim_var_string(VV_FNAME_NEW, newfile, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
407 set_vim_var_string(VV_FNAME_OUT, outfile, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
408 (void)eval_to_bool(p_dex, &err, NULL, FALSE);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
409 set_vim_var_string(VV_FNAME_IN, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
410 set_vim_var_string(VV_FNAME_NEW, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
411 set_vim_var_string(VV_FNAME_OUT, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
412 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
413
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
414 void
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
415 eval_patch(
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
416 char_u *origfile,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
417 char_u *difffile,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
418 char_u *outfile)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
419 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
420 int err;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
421
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
422 set_vim_var_string(VV_FNAME_IN, origfile, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
423 set_vim_var_string(VV_FNAME_DIFF, difffile, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
424 set_vim_var_string(VV_FNAME_OUT, outfile, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
425 (void)eval_to_bool(p_pex, &err, NULL, FALSE);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
426 set_vim_var_string(VV_FNAME_IN, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
427 set_vim_var_string(VV_FNAME_DIFF, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
428 set_vim_var_string(VV_FNAME_OUT, NULL, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
429 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
430 # endif
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
431
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
432 #if defined(FEAT_SPELL) || defined(PROTO)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
433 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
434 * Evaluate an expression to a list with suggestions.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
435 * For the "expr:" part of 'spellsuggest'.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
436 * Returns NULL when there is an error.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
437 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
438 list_T *
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
439 eval_spell_expr(char_u *badword, char_u *expr)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
440 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
441 typval_T save_val;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
442 typval_T rettv;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
443 list_T *list = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
444 char_u *p = skipwhite(expr);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
445
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
446 // Set "v:val" to the bad word.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
447 prepare_vimvar(VV_VAL, &save_val);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
448 set_vim_var_string(VV_VAL, badword, -1);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
449 if (p_verbose == 0)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
450 ++emsg_off;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
451
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
452 if (eval1(&p, &rettv, TRUE) == OK)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
453 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
454 if (rettv.v_type != VAR_LIST)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
455 clear_tv(&rettv);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
456 else
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
457 list = rettv.vval.v_list;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
458 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
459
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
460 if (p_verbose == 0)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
461 --emsg_off;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
462 clear_tv(get_vim_var_tv(VV_VAL));
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
463 restore_vimvar(VV_VAL, &save_val);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
464
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
465 return list;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
466 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
467
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
468 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
469 * "list" is supposed to contain two items: a word and a number. Return the
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
470 * word in "pp" and the number as the return value.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
471 * Return -1 if anything isn't right.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
472 * Used to get the good word and score from the eval_spell_expr() result.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
473 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
474 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
475 get_spellword(list_T *list, char_u **pp)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
476 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
477 listitem_T *li;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
478
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
479 li = list->lv_first;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
480 if (li == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
481 return -1;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
482 *pp = tv_get_string(&li->li_tv);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
483
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
484 li = li->li_next;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
485 if (li == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
486 return -1;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
487 return (int)tv_get_number(&li->li_tv);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
488 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
489 #endif
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
490
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
491 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
492 * Prepare v: variable "idx" to be used.
17944
745c02392844 patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
493 * Save the current typeval in "save_tv" and clear it.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
494 * When not used yet add the variable to the v: hashtable.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
495 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
496 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
497 prepare_vimvar(int idx, typval_T *save_tv)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
498 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
499 *save_tv = vimvars[idx].vv_tv;
17944
745c02392844 patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
500 vimvars[idx].vv_str = NULL; // don't free it now
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
501 if (vimvars[idx].vv_type == VAR_UNKNOWN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
502 hash_add(&vimvarht, vimvars[idx].vv_di.di_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
503 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
504
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
505 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
506 * Restore v: variable "idx" to typeval "save_tv".
17944
745c02392844 patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
507 * Note that the v: variable must have been cleared already.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
508 * When no longer defined, remove the variable from the v: hashtable.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
509 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
510 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
511 restore_vimvar(int idx, typval_T *save_tv)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
512 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
513 hashitem_T *hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
514
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
515 vimvars[idx].vv_tv = *save_tv;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
516 if (vimvars[idx].vv_type == VAR_UNKNOWN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
517 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
518 hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
519 if (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
520 internal_error("restore_vimvar()");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
521 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
522 hash_remove(&vimvarht, hi);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
523 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
524 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
525
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
526 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
527 * List Vim variables.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
528 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
529 static void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
530 list_vim_vars(int *first)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
531 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
532 list_hashtable_vars(&vimvarht, "v:", FALSE, first);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
533 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
534
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
535 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
536 * List script-local variables, if there is a script.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
537 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
538 static void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
539 list_script_vars(int *first)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
540 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
541 if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
542 list_hashtable_vars(&SCRIPT_VARS(current_sctx.sc_sid),
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
543 "s:", FALSE, first);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
544 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
545
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
546 /*
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 * Get a list of lines from a HERE document. The here document is a list of
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 * lines surrounded by a marker.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 * cmd << {marker}
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 * {line1}
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 * {line2}
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 * ....
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 * {marker}
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 * The {marker} is a string. If the optional 'trim' word is supplied before the
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 * marker, then the leading indentation before the lines (matching the
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 * indentation in the 'cmd' line) is stripped.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 * Returns a List with {lines} or NULL.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 static list_T *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 heredoc_get(exarg_T *eap, char_u *cmd)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 char_u *theline;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 char_u *marker;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 list_T *l;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 char_u *p;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 int marker_indent_len = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 int text_indent_len = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 char_u *text_indent = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if (eap->getline == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 emsg(_("E991: cannot use =<< here"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 // Check for the optional 'trim' word before the marker
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 cmd = skipwhite(cmd);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (STRNCMP(cmd, "trim", 4) == 0 && (cmd[4] == NUL || VIM_ISWHITE(cmd[4])))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 cmd = skipwhite(cmd + 4);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 // Trim the indentation from all the lines in the here document.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 // The amount of indentation trimmed is the same as the indentation of
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 // the first line after the :let command line. To find the end marker
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 // the indent of the :let command line is trimmed.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 p = *eap->cmdlinep;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 while (VIM_ISWHITE(*p))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 p++;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 marker_indent_len++;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 text_indent_len = -1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 // The marker is the next word.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 if (*cmd != NUL && *cmd != '"')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 marker = skipwhite(cmd);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 p = skiptowhite(marker);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 if (*skipwhite(p) != NUL && *skipwhite(p) != '"')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 emsg(_(e_trailing));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 *p = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 if (vim_islower(*marker))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 emsg(_("E221: Marker cannot start with lower case letter"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 emsg(_("E172: Missing marker"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 l = list_alloc();
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 if (l == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 for (;;)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 int mi = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 int ti = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 theline = eap->getline(NUL, eap->cookie, 0, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 if (theline == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 semsg(_("E990: Missing end marker '%s'"), marker);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 // with "trim": skip the indent matching the :let line to find the
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 // marker
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 if (marker_indent_len > 0
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 && STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 mi = marker_indent_len;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 if (STRCMP(marker, theline + mi) == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 vim_free(theline);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 if (text_indent_len == -1 && *theline != NUL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 // set the text indent from the first line.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 p = theline;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 text_indent_len = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 while (VIM_ISWHITE(*p))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 p++;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 text_indent_len++;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 text_indent = vim_strnsave(theline, text_indent_len);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 // with "trim": skip the indent matching the first line
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 if (text_indent != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 for (ti = 0; ti < text_indent_len; ++ti)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 if (theline[ti] != text_indent[ti])
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 if (list_append_string(l, theline + ti, -1) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 vim_free(theline);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 vim_free(text_indent);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 return l;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 * ":let" list all variable values
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 * ":let var1 var2" list variable values
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 * ":let var = expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 * ":let var += expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 * ":let var -= expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 * ":let var *= expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 * ":let var /= expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 * ":let var %= expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 * ":let var .= expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 * ":let var ..= expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 * ":let [var1, var2] = expr" unpack list.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 ex_let(exarg_T *eap)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 ex_let_const(eap, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 * ":const" list all variable values
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 * ":const var1 var2" list variable values
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 * ":const var = expr" assignment command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 * ":const [var1, var2] = expr" unpack list.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 ex_const(exarg_T *eap)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 ex_let_const(eap, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 ex_let_const(exarg_T *eap, int is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 char_u *arg = eap->arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 char_u *expr = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 typval_T rettv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 int i;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 int var_count = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 int semicolon = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 char_u op[2];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 char_u *argend;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 int first = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 int concat;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 argend = skip_var_list(arg, &var_count, &semicolon);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 if (argend == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 if (argend > arg && argend[-1] == '.') // for var.='str'
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 --argend;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 expr = skipwhite(argend);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 concat = expr[0] == '.'
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 && ((expr[1] == '=' && current_sctx.sc_version < 2)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 || (expr[1] == '.' && expr[2] == '='));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%", *expr) != NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 && expr[1] == '=') || concat))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 // ":let" without "=": list variables
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 if (*arg == '[')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 emsg(_(e_invarg));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 else if (expr[0] == '.')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 emsg(_("E985: .= is not supported with script version 2"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 else if (!ends_excmd(*arg))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 // ":let var1 var2"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 arg = list_arg_vars(eap, arg, &first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 else if (!eap->skip)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 // ":let"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 list_glob_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 list_buf_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 list_win_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 list_tab_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 list_script_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 list_func_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 list_vim_vars(&first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 eap->nextcmd = check_nextcmd(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 list_T *l;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 // HERE document
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 l = heredoc_get(eap, expr + 3);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 if (l != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 rettv_list_set(&rettv, l);
18348
9ea364ccf216 patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents: 17986
diff changeset
760 if (!eap->skip)
9ea364ccf216 patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents: 17986
diff changeset
761 {
9ea364ccf216 patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents: 17986
diff changeset
762 op[0] = '=';
9ea364ccf216 patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents: 17986
diff changeset
763 op[1] = NUL;
9ea364ccf216 patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents: 17986
diff changeset
764 (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count,
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 is_const, op);
18348
9ea364ccf216 patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents: 17986
diff changeset
766 }
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 clear_tv(&rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 op[0] = '=';
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 op[1] = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 if (*expr != '=')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 op[0] = *expr; // +=, -=, *=, /=, %= or .=
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 if (expr[0] == '.' && expr[1] == '.') // ..=
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 ++expr;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 expr = skipwhite(expr + 2);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 expr = skipwhite(expr + 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 if (eap->skip)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 ++emsg_skip;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 if (eap->skip)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 if (i != FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 clear_tv(&rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 --emsg_skip;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 else if (i != FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 is_const, op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 clear_tv(&rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 * Assign the typevalue "tv" to the variable or variables at "arg_start".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 * Handles both "var" with any type and "[var, var; var]" with a list type.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 * When "op" is not NULL it points to a string with characters that
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 * must appear after the variable(s). Use "+", "-" or "." for add, subtract
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 * or concatenate.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 * Returns OK or FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 ex_let_vars(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 char_u *arg_start,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 typval_T *tv,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 int copy, // copy values from "tv", don't move
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 int semicolon, // from skip_var_list()
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 int var_count, // from skip_var_list()
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 int is_const, // lock variables for const
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 char_u *op)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 char_u *arg = arg_start;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 list_T *l;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 int i;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 listitem_T *item;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 typval_T ltv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 if (*arg != '[')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 // ":let var = expr" or ":for var in list"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 if (ex_let_one(arg, tv, copy, is_const, op, op) == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 return OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 // ":let [v1, v2] = list" or ":for [v1, v2] in listlist"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 if (tv->v_type != VAR_LIST || (l = tv->vval.v_list) == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 emsg(_(e_listreq));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 i = list_len(l);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 if (semicolon == 0 && var_count < i)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 emsg(_("E687: Less targets than List items"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 if (var_count - semicolon > i)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 emsg(_("E688: More targets than List items"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 item = l->lv_first;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 while (*arg != ']')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 arg = skipwhite(arg + 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 arg = ex_let_one(arg, &item->li_tv, TRUE, is_const,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 (char_u *)",;]", op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 item = item->li_next;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 if (arg == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 arg = skipwhite(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 if (*arg == ';')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 // Put the rest of the list (may be empty) in the var after ';'.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 // Create a new list for this.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 l = list_alloc();
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 if (l == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 while (item != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 list_append_tv(l, &item->li_tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 item = item->li_next;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 ltv.v_type = VAR_LIST;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 ltv.v_lock = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 ltv.vval.v_list = l;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 l->lv_refcount = 1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 arg = ex_let_one(skipwhite(arg + 1), &ltv, FALSE, is_const,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 (char_u *)"]", op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 clear_tv(&ltv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 if (arg == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 else if (*arg != ',' && *arg != ']')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 internal_error("ex_let_vars()");
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 return OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 * Skip over assignable variable "var" or list of variables "[var, var]".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 * Used for ":let varvar = expr" and ":for varvar in expr".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 * For "[var, var]" increment "*var_count" for each variable.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 * for "[var, var; var]" set "semicolon".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 * Return NULL for an error.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 char_u *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 skip_var_list(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 char_u *arg,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 int *var_count,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 int *semicolon)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 char_u *p, *s;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 if (*arg == '[')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 // "[var, var]": find the matching ']'.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 p = arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 for (;;)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 p = skipwhite(p + 1); // skip whites after '[', ';' or ','
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 s = skip_var_one(p);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 if (s == p)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 semsg(_(e_invarg2), p);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 ++*var_count;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 p = skipwhite(s);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 if (*p == ']')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 else if (*p == ';')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 if (*semicolon == 1)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 emsg(_("Double ; in list of variables"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 *semicolon = 1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 else if (*p != ',')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 semsg(_(e_invarg2), p);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 return p + 1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 return skip_var_one(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 * Skip one (assignable) variable name, including @r, $VAR, &option, d.key,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 * l[idx].
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 static char_u *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 skip_var_one(char_u *arg)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 if (*arg == '@' && arg[1] != NUL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 return arg + 2;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 * List variables for hashtab "ht" with prefix "prefix".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 * If "empty" is TRUE also list NULL strings as empty strings.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 list_hashtable_vars(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 hashtab_T *ht,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 char *prefix,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 int empty,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 hashitem_T *hi;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 dictitem_T *di;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 int todo;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 char_u buf[IOSIZE];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 todo = (int)ht->ht_used;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 if (!HASHITEM_EMPTY(hi))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 --todo;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 di = HI2DI(hi);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 // apply :filter /pat/ to variable name
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 vim_strncpy((char_u *)buf, (char_u *)prefix, IOSIZE - 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 vim_strcat((char_u *)buf, di->di_key, IOSIZE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 if (message_filtered(buf))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 continue;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 if (empty || di->di_tv.v_type != VAR_STRING
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 || di->di_tv.vval.v_string != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 list_one_var(di, prefix, first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 * List global variables.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 list_glob_vars(int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 list_hashtable_vars(&globvarht, "", TRUE, first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 * List buffer variables.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 list_buf_vars(int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 list_hashtable_vars(&curbuf->b_vars->dv_hashtab, "b:", TRUE, first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 * List window variables.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 list_win_vars(int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 list_hashtable_vars(&curwin->w_vars->dv_hashtab, "w:", TRUE, first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 * List tab page variables.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 list_tab_vars(int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 list_hashtable_vars(&curtab->tp_vars->dv_hashtab, "t:", TRUE, first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 * List variables in "arg".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 static char_u *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 list_arg_vars(exarg_T *eap, char_u *arg, int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 int error = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 int len;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 char_u *name;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 char_u *name_start;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 char_u *arg_subsc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 char_u *tofree;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 typval_T tv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 while (!ends_excmd(*arg) && !got_int)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 if (error || eap->skip)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 arg = find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 if (!VIM_ISWHITE(*arg) && !ends_excmd(*arg))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 emsg_severe = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 emsg(_(e_trailing));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 // get_name_len() takes care of expanding curly braces
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 name_start = name = arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 len = get_name_len(&arg, &tofree, TRUE, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 if (len <= 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 // This is mainly to keep test 49 working: when expanding
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 // curly braces fails overrule the exception error message.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 if (len < 0 && !aborting())
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 emsg_severe = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 semsg(_(e_invarg2), arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 error = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 if (tofree != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 name = tofree;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 if (get_var_tv(name, len, &tv, NULL, TRUE, FALSE) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 error = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 // handle d.key, l[idx], f(expr)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 arg_subsc = arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 if (handle_subscript(&arg, &tv, TRUE, TRUE,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 name, &name) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 error = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 if (arg == arg_subsc && len == 2 && name[1] == ':')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 switch (*name)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 case 'g': list_glob_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 case 'b': list_buf_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 case 'w': list_win_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 case 't': list_tab_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 case 'v': list_vim_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 case 's': list_script_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 case 'l': list_func_vars(first); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 default:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 semsg(_("E738: Can't list variables for %s"), name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 char_u numbuf[NUMBUFLEN];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 char_u *tf;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 int c;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 char_u *s;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 s = echo_string(&tv, &tf, numbuf, 0);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 c = *arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 *arg = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 list_one_var_a("",
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 arg == arg_subsc ? name : name_start,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 tv.v_type,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 s == NULL ? (char_u *)"" : s,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 *arg = c;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 vim_free(tf);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 clear_tv(&tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 vim_free(tofree);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 arg = skipwhite(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 return arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 * Set one item of ":let var = expr" or ":let [v1, v2] = list" to its value.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 * Returns a pointer to the char just after the var name.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 * Returns NULL if there is an error.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 static char_u *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 ex_let_one(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 char_u *arg, // points to variable name
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 typval_T *tv, // value to assign to variable
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 int copy, // copy value from "tv"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 int is_const, // lock variable for const
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 char_u *endchars, // valid chars after variable name or NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 char_u *op) // "+", "-", "." or NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 int c1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 char_u *name;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 char_u *p;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 char_u *arg_end = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 int len;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 int opt_flags;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 char_u *tofree = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 // ":let $VAR = expr": Set environment variable.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 if (*arg == '$')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 if (is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 emsg(_("E996: Cannot lock an environment variable"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 // Find the end of the name.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 ++arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 name = arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 len = get_env_len(&arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 if (len == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 semsg(_(e_invarg2), name - 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 semsg(_(e_letwrong), op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 else if (endchars != NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 && vim_strchr(endchars, *skipwhite(arg)) == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 emsg(_(e_letunexp));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 else if (!check_secure())
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 c1 = name[len];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 name[len] = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 p = tv_get_string_chk(tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 if (p != NULL && op != NULL && *op == '.')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 int mustfree = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 char_u *s = vim_getenv(name, &mustfree);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 if (s != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 p = tofree = concat_str(s, p);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 if (mustfree)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 vim_free(s);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 if (p != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 vim_setenv(name, p);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 if (STRICMP(name, "HOME") == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 init_homedir();
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 else if (didset_vim && STRICMP(name, "VIM") == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 didset_vim = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 else if (didset_vimruntime
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 && STRICMP(name, "VIMRUNTIME") == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 didset_vimruntime = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 arg_end = arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 name[len] = c1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 vim_free(tofree);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 // ":let &option = expr": Set option value.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 // ":let &l:option = expr": Set local option value.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 // ":let &g:option = expr": Set global option value.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 else if (*arg == '&')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 if (is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 emsg(_("E996: Cannot lock an option"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 // Find the end of the name.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 p = find_option_end(&arg, &opt_flags);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 if (p == NULL || (endchars != NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 && vim_strchr(endchars, *skipwhite(p)) == NULL))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 emsg(_(e_letunexp));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 long n;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 int opt_type;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 long numval;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 char_u *stringval = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 char_u *s;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 c1 = *p;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 *p = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 n = (long)tv_get_number(tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 s = tv_get_string_chk(tv); // != NULL if number or string
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 if (s != NULL && op != NULL && *op != '=')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 opt_type = get_option_value(arg, &numval,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 &stringval, opt_flags);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 if ((opt_type == 1 && *op == '.')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 || (opt_type == 0 && *op != '.'))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 semsg(_(e_letwrong), op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 s = NULL; // don't set the value
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 if (opt_type == 1) // number
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 switch (*op)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 case '+': n = numval + n; break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 case '-': n = numval - n; break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 case '*': n = numval * n; break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 case '/': n = (long)num_divide(numval, n); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 case '%': n = (long)num_modulus(numval, n); break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 else if (opt_type == 0 && stringval != NULL) // string
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 s = concat_str(stringval, s);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 vim_free(stringval);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 stringval = s;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 if (s != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 set_option_value(arg, n, s, opt_flags);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 arg_end = p;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 *p = c1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 vim_free(stringval);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 // ":let @r = expr": Set register contents.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 else if (*arg == '@')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 if (is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 emsg(_("E996: Cannot lock a register"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 ++arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 semsg(_(e_letwrong), op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 else if (endchars != NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 emsg(_(e_letunexp));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 char_u *ptofree = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 char_u *s;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 p = tv_get_string_chk(tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 if (p != NULL && op != NULL && *op == '.')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 s = get_reg_contents(*arg == '@' ? '"' : *arg, GREG_EXPR_SRC);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 if (s != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 p = ptofree = concat_str(s, p);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 vim_free(s);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 if (p != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 arg_end = arg + 1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 vim_free(ptofree);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 // ":let var = expr": Set internal variable.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 // ":let {expr} = expr": Idem, name made with curly braces
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 else if (eval_isnamec1(*arg) || *arg == '{')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 lval_T lv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 p = get_lval(arg, tv, &lv, FALSE, FALSE, 0, FNE_CHECK_START);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 if (p != NULL && lv.ll_name != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 emsg(_(e_letunexp));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 set_var_lval(&lv, p, tv, copy, is_const, op);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 arg_end = p;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 clear_lval(&lv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 semsg(_(e_invarg2), arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 return arg_end;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 * ":unlet[!] var1 ... " command.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 ex_unlet(exarg_T *eap)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 ex_unletlock(eap, eap->arg, 0);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 * ":lockvar" and ":unlockvar" commands
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 ex_lockvar(exarg_T *eap)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 char_u *arg = eap->arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 int deep = 2;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 if (eap->forceit)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 deep = -1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 else if (vim_isdigit(*arg))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 deep = getdigits(&arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 arg = skipwhite(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 ex_unletlock(eap, arg, deep);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 * ":unlet", ":lockvar" and ":unlockvar" are quite similar.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 ex_unletlock(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 exarg_T *eap,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 char_u *argstart,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 int deep)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 char_u *arg = argstart;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 char_u *name_end;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 int error = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 lval_T lv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 do
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 if (*arg == '$')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 char_u *name = ++arg;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 if (get_env_len(&arg) == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 semsg(_(e_invarg2), name - 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 vim_unsetenv(name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 arg = skipwhite(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 continue;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 // Parse the name and find the end.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, 0,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 FNE_CHECK_START);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 if (lv.ll_name == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 error = TRUE; // error but continue parsing
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 if (name_end == NULL || (!VIM_ISWHITE(*name_end)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 && !ends_excmd(*name_end)))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 if (name_end != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 emsg_severe = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 emsg(_(e_trailing));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 if (!(eap->skip || error))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 clear_lval(&lv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 if (!error && !eap->skip)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 if (eap->cmdidx == CMD_unlet)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 if (do_unlet_var(&lv, name_end, eap->forceit) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 error = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 if (do_lock_var(&lv, name_end, deep,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 eap->cmdidx == CMD_lockvar) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 error = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 if (!eap->skip)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 clear_lval(&lv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 arg = skipwhite(name_end);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 } while (!ends_excmd(*arg));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 eap->nextcmd = check_nextcmd(arg);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 static int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 do_unlet_var(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 lval_T *lp,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 char_u *name_end,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 int forceit)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 int ret = OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 int cc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 if (lp->ll_tv == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 cc = *name_end;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 *name_end = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 // Normal name or expanded name.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 if (do_unlet(lp->ll_name, forceit) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 ret = FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 *name_end = cc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 else if ((lp->ll_list != NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 && var_check_lock(lp->ll_list->lv_lock, lp->ll_name, FALSE))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 || (lp->ll_dict != NULL
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 && var_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE)))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 else if (lp->ll_range)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 listitem_T *li;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 listitem_T *ll_li = lp->ll_li;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 int ll_n1 = lp->ll_n1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 while (ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= ll_n1))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 li = ll_li->li_next;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 if (var_check_lock(ll_li->li_tv.v_lock, lp->ll_name, FALSE))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 ll_li = li;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 ++ll_n1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 // Delete a range of List items.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 while (lp->ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 li = lp->ll_li->li_next;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 listitem_remove(lp->ll_list, lp->ll_li);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 lp->ll_li = li;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 ++lp->ll_n1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 if (lp->ll_list != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 // unlet a List item.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 listitem_remove(lp->ll_list, lp->ll_li);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 // unlet a Dictionary item.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 dictitem_remove(lp->ll_dict, lp->ll_di);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 return ret;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 * "unlet" a variable. Return OK if it existed, FAIL if not.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 * When "forceit" is TRUE don't complain if the variable doesn't exist.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 do_unlet(char_u *name, int forceit)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 hashtab_T *ht;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 hashitem_T *hi;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 char_u *varname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 dict_T *d;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 dictitem_T *di;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 ht = find_var_ht(name, &varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 if (ht != NULL && *varname != NUL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 d = get_current_funccal_dict(ht);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 if (d == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 if (ht == &globvarht)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 d = &globvardict;
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1541 else if (ht == &compat_hashtab)
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 d = &vimvardict;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 di = find_var_in_ht(ht, *name, (char_u *)"", FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 d = di == NULL ? NULL : di->di_tv.vval.v_dict;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 if (d == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 internal_error("do_unlet()");
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 hi = hash_find(ht, varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 if (HASHITEM_EMPTY(hi))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 hi = find_hi_in_scoped_ht(name, &ht);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 if (hi != NULL && !HASHITEM_EMPTY(hi))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 di = HI2DI(hi);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 if (var_check_fixed(di->di_flags, name, FALSE)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 || var_check_ro(di->di_flags, name, FALSE)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 || var_check_lock(d->dv_lock, name, FALSE))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 delete_var(ht, hi);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 return OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 if (forceit)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 return OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 semsg(_("E108: No such variable: \"%s\""), name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 return FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 * Lock or unlock variable indicated by "lp".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 * "deep" is the levels to go (-1 for unlimited);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 * "lock" is TRUE for ":lockvar", FALSE for ":unlockvar".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 static int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 do_lock_var(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 lval_T *lp,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 char_u *name_end,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 int deep,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 int lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 int ret = OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 int cc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 dictitem_T *di;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 if (deep == 0) // nothing to do
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 return OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 if (lp->ll_tv == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 cc = *name_end;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 *name_end = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 // Normal name or expanded name.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 di = find_var(lp->ll_name, NULL, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 if (di == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 ret = FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 else if ((di->di_flags & DI_FLAGS_FIX)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 && di->di_tv.v_type != VAR_DICT
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 && di->di_tv.v_type != VAR_LIST)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 // For historic reasons this error is not given for a list or dict.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 // E.g., the b: dict could be locked/unlocked.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 semsg(_("E940: Cannot lock or unlock variable %s"), lp->ll_name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 if (lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 di->di_flags |= DI_FLAGS_LOCK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 di->di_flags &= ~DI_FLAGS_LOCK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 item_lock(&di->di_tv, deep, lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 *name_end = cc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 else if (lp->ll_range)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 listitem_T *li = lp->ll_li;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 // (un)lock a range of List items.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 while (li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 item_lock(&li->li_tv, deep, lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 li = li->li_next;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 ++lp->ll_n1;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 else if (lp->ll_list != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 // (un)lock a List item.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 item_lock(&lp->ll_li->li_tv, deep, lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 // (un)lock a Dictionary item.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 item_lock(&lp->ll_di->di_tv, deep, lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 return ret;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 * Lock or unlock an item. "deep" is nr of levels to go.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 item_lock(typval_T *tv, int deep, int lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 static int recurse = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 list_T *l;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 listitem_T *li;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 dict_T *d;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 blob_T *b;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 hashitem_T *hi;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 int todo;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 if (recurse >= DICT_MAXNEST)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 emsg(_("E743: variable nested too deep for (un)lock"));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 if (deep == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 ++recurse;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 // lock/unlock the item itself
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 if (lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 tv->v_lock |= VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 tv->v_lock &= ~VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 switch (tv->v_type)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 case VAR_UNKNOWN:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 case VAR_NUMBER:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 case VAR_STRING:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 case VAR_FUNC:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 case VAR_PARTIAL:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 case VAR_FLOAT:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 case VAR_SPECIAL:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 case VAR_JOB:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 case VAR_CHANNEL:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 case VAR_BLOB:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 if ((b = tv->vval.v_blob) != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 if (lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 b->bv_lock |= VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 b->bv_lock &= ~VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 case VAR_LIST:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 if ((l = tv->vval.v_list) != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 if (lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 l->lv_lock |= VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 l->lv_lock &= ~VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 if (deep < 0 || deep > 1)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 // recursive: lock/unlock the items the List contains
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 for (li = l->lv_first; li != NULL; li = li->li_next)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 item_lock(&li->li_tv, deep - 1, lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 break;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 case VAR_DICT:
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 if ((d = tv->vval.v_dict) != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 if (lock)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 d->dv_lock |= VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 d->dv_lock &= ~VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 if (deep < 0 || deep > 1)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 // recursive: lock/unlock the items the List contains
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 todo = (int)d->dv_hashtab.ht_used;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 if (!HASHITEM_EMPTY(hi))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 --todo;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 item_lock(&HI2DI(hi)->di_tv, deep - 1, lock);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 --recurse;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1730 #if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1731 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1732 * Delete all "menutrans_" variables.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1733 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1734 void
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1735 del_menutrans_vars(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1736 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1737 hashitem_T *hi;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1738 int todo;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1739
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1740 hash_lock(&globvarht);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1741 todo = (int)globvarht.ht_used;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1742 for (hi = globvarht.ht_array; todo > 0 && !got_int; ++hi)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1743 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1744 if (!HASHITEM_EMPTY(hi))
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1745 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1746 --todo;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1747 if (STRNCMP(HI2DI(hi)->di_key, "menutrans_", 10) == 0)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1748 delete_var(&globvarht, hi);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1749 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1750 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1751 hash_unlock(&globvarht);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1752 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1753 #endif
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1754
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 /*
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1756 * Local string buffer for the next two functions to store a variable name
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1757 * with its prefix. Allocated in cat_prefix_varname(), freed later in
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1758 * get_user_var_name().
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1759 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1760
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1761 static char_u *varnamebuf = NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1762 static int varnamebuflen = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1763
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1764 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1765 * Function to concatenate a prefix and a variable name.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1766 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1767 static char_u *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1768 cat_prefix_varname(int prefix, char_u *name)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1769 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1770 int len;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1771
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1772 len = (int)STRLEN(name) + 3;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1773 if (len > varnamebuflen)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1774 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1775 vim_free(varnamebuf);
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
1776 len += 10; // some additional space
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1777 varnamebuf = alloc(len);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1778 if (varnamebuf == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1779 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1780 varnamebuflen = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1781 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1782 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1783 varnamebuflen = len;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1784 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1785 *varnamebuf = prefix;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1786 varnamebuf[1] = ':';
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1787 STRCPY(varnamebuf + 2, name);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1788 return varnamebuf;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1789 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1790
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1791 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1792 * Function given to ExpandGeneric() to obtain the list of user defined
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1793 * (global/buffer/window/built-in) variable names.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1794 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1795 char_u *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1796 get_user_var_name(expand_T *xp, int idx)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1797 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1798 static long_u gdone;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1799 static long_u bdone;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1800 static long_u wdone;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1801 static long_u tdone;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1802 static int vidx;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1803 static hashitem_T *hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1804 hashtab_T *ht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1805
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1806 if (idx == 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1807 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1808 gdone = bdone = wdone = vidx = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1809 tdone = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1810 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1811
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1812 // Global variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1813 if (gdone < globvarht.ht_used)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1814 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1815 if (gdone++ == 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1816 hi = globvarht.ht_array;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1817 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1818 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1819 while (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1820 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1821 if (STRNCMP("g:", xp->xp_pattern, 2) == 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1822 return cat_prefix_varname('g', hi->hi_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1823 return hi->hi_key;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1824 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1825
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1826 // b: variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1827 ht = &curbuf->b_vars->dv_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1828 if (bdone < ht->ht_used)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1829 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1830 if (bdone++ == 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1831 hi = ht->ht_array;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1832 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1833 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1834 while (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1835 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1836 return cat_prefix_varname('b', hi->hi_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1837 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1838
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1839 // w: variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1840 ht = &curwin->w_vars->dv_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1841 if (wdone < ht->ht_used)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1842 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1843 if (wdone++ == 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1844 hi = ht->ht_array;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1845 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1846 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1847 while (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1848 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1849 return cat_prefix_varname('w', hi->hi_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1850 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1851
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1852 // t: variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1853 ht = &curtab->tp_vars->dv_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1854 if (tdone < ht->ht_used)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1855 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1856 if (tdone++ == 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1857 hi = ht->ht_array;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1858 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1859 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1860 while (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1861 ++hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1862 return cat_prefix_varname('t', hi->hi_key);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1863 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1864
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1865 // v: variables
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1866 if (vidx < VV_LEN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1867 return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1868
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1869 VIM_CLEAR(varnamebuf);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1870 varnamebuflen = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1871 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1872 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1873
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1874 char *
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1875 get_var_special_name(int nr)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1876 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1877 switch (nr)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1878 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1879 case VVAL_FALSE: return "v:false";
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1880 case VVAL_TRUE: return "v:true";
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1881 case VVAL_NONE: return "v:none";
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1882 case VVAL_NULL: return "v:null";
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1883 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1884 internal_error("get_var_special_name()");
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1885 return "42";
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1886 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1887
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1888 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1889 * Returns the global variable dictionary
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1890 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1891 dict_T *
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1892 get_globvar_dict(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1893 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1894 return &globvardict;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1895 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1896
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1897 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1898 * Returns the global variable hash table
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1899 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1900 hashtab_T *
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1901 get_globvar_ht(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1902 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1903 return &globvarht;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1904 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1905
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1906 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1907 * Returns the v: variable dictionary
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1908 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1909 dict_T *
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1910 get_vimvar_dict(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1911 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1912 return &vimvardict;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1913 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
1914
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1915 /*
17887
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1916 * Set type of v: variable to "type".
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1917 */
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1918 void
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1919 set_vim_var_type(int idx, vartype_T type)
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1920 {
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1921 vimvars[idx].vv_type = type;
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1922 }
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1923
39ffd167a307 patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents: 17885
diff changeset
1924 /*
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1925 * Set number v: variable to "val".
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
1926 * Note that this does not set the type, use set_vim_var_type() for that.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1927 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1928 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1929 set_vim_var_nr(int idx, varnumber_T val)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1930 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1931 vimvars[idx].vv_nr = val;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1932 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1933
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1934 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1935 * Get typval_T v: variable value.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1936 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1937 typval_T *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1938 get_vim_var_tv(int idx)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1939 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1940 return &vimvars[idx].vv_tv;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1941 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1942
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1943 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1944 * Get number v: variable value.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1945 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1946 varnumber_T
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1947 get_vim_var_nr(int idx)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1948 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1949 return vimvars[idx].vv_nr;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1950 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1951
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1952 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1953 * Get string v: variable value. Uses a static buffer, can only be used once.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1954 * If the String variable has never been set, return an empty string.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1955 * Never returns NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1956 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1957 char_u *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1958 get_vim_var_str(int idx)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1959 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1960 return tv_get_string(&vimvars[idx].vv_tv);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1961 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1962
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1963 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1964 * Get List v: variable value. Caller must take care of reference count when
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1965 * needed.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1966 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1967 list_T *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1968 get_vim_var_list(int idx)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1969 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1970 return vimvars[idx].vv_list;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1971 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1972
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1973 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1974 * Get Dict v: variable value. Caller must take care of reference count when
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1975 * needed.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1976 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1977 dict_T *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1978 get_vim_var_dict(int idx)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1979 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1980 return vimvars[idx].vv_dict;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1981 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1982
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1983 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1984 * Set v:char to character "c".
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1985 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1986 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1987 set_vim_var_char(int c)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1988 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1989 char_u buf[MB_MAXBYTES + 1];
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1990
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1991 if (has_mbyte)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1992 buf[(*mb_char2bytes)(c, buf)] = NUL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1993 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1994 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1995 buf[0] = c;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1996 buf[1] = NUL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1997 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1998 set_vim_var_string(VV_CHAR, buf, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
1999 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2000
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2001 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2002 * Set v:count to "count" and v:count1 to "count1".
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2003 * When "set_prevcount" is TRUE first set v:prevcount from v:count.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2004 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2005 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2006 set_vcount(
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2007 long count,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2008 long count1,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2009 int set_prevcount)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2010 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2011 if (set_prevcount)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2012 vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2013 vimvars[VV_COUNT].vv_nr = count;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2014 vimvars[VV_COUNT1].vv_nr = count1;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2015 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2016
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2017 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2018 * Save variables that might be changed as a side effect. Used when executing
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2019 * a timer callback.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2020 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2021 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2022 save_vimvars(vimvars_save_T *vvsave)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2023 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2024 vvsave->vv_prevcount = vimvars[VV_PREVCOUNT].vv_nr;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2025 vvsave->vv_count = vimvars[VV_COUNT].vv_nr;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2026 vvsave->vv_count1 = vimvars[VV_COUNT1].vv_nr;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2027 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2028
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2029 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2030 * Restore variables saved by save_vimvars().
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2031 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2032 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2033 restore_vimvars(vimvars_save_T *vvsave)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2034 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2035 vimvars[VV_PREVCOUNT].vv_nr = vvsave->vv_prevcount;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2036 vimvars[VV_COUNT].vv_nr = vvsave->vv_count;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2037 vimvars[VV_COUNT1].vv_nr = vvsave->vv_count1;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2038 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2039
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2040 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2041 * Set string v: variable to a copy of "val". If 'copy' is FALSE, then set the
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2042 * value.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2043 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2044 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2045 set_vim_var_string(
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2046 int idx,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2047 char_u *val,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2048 int len) // length of "val" to use or -1 (whole string)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2049 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2050 clear_tv(&vimvars[idx].vv_di.di_tv);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2051 vimvars[idx].vv_type = VAR_STRING;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2052 if (val == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2053 vimvars[idx].vv_str = NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2054 else if (len == -1)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2055 vimvars[idx].vv_str = vim_strsave(val);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2056 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2057 vimvars[idx].vv_str = vim_strnsave(val, len);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2058 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2059
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2060 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2061 * Set List v: variable to "val".
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2062 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2063 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2064 set_vim_var_list(int idx, list_T *val)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2065 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2066 clear_tv(&vimvars[idx].vv_di.di_tv);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2067 vimvars[idx].vv_type = VAR_LIST;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2068 vimvars[idx].vv_list = val;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2069 if (val != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2070 ++val->lv_refcount;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2071 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2072
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2073 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2074 * Set Dictionary v: variable to "val".
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2075 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2076 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2077 set_vim_var_dict(int idx, dict_T *val)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2078 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2079 clear_tv(&vimvars[idx].vv_di.di_tv);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2080 vimvars[idx].vv_type = VAR_DICT;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2081 vimvars[idx].vv_dict = val;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2082 if (val != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2083 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2084 ++val->dv_refcount;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2085 dict_set_items_ro(val);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2086 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2087 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2088
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2089 /*
18477
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2090 * Set the v:argv list.
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2091 */
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2092 void
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2093 set_argv_var(char **argv, int argc)
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2094 {
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2095 list_T *l = list_alloc();
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2096 int i;
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2097
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2098 if (l == NULL)
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2099 getout(1);
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2100 l->lv_lock = VAR_FIXED;
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2101 for (i = 0; i < argc; ++i)
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2102 {
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2103 if (list_append_string(l, (char_u *)argv[i], -1) == FAIL)
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2104 getout(1);
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2105 l->lv_last->li_tv.v_lock = VAR_FIXED;
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2106 }
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2107 set_vim_var_list(VV_ARGV, l);
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2108 }
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2109
e93cab5d0f0f patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 18348
diff changeset
2110 /*
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2111 * Set v:register if needed.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2112 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2113 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2114 set_reg_var(int c)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2115 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2116 char_u regname;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2117
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2118 if (c == 0 || c == ' ')
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2119 regname = '"';
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2120 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2121 regname = c;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2122 // Avoid free/alloc when the value is already right.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2123 if (vimvars[VV_REG].vv_str == NULL || vimvars[VV_REG].vv_str[0] != c)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2124 set_vim_var_string(VV_REG, &regname, 1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2125 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2126
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2127 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2128 * Get or set v:exception. If "oldval" == NULL, return the current value.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2129 * Otherwise, restore the value to "oldval" and return NULL.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2130 * Must always be called in pairs to save and restore v:exception! Does not
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2131 * take care of memory allocations.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2132 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2133 char_u *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2134 v_exception(char_u *oldval)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2135 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2136 if (oldval == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2137 return vimvars[VV_EXCEPTION].vv_str;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2138
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2139 vimvars[VV_EXCEPTION].vv_str = oldval;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2140 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2141 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2142
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2143 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2144 * Get or set v:throwpoint. If "oldval" == NULL, return the current value.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2145 * Otherwise, restore the value to "oldval" and return NULL.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2146 * Must always be called in pairs to save and restore v:throwpoint! Does not
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2147 * take care of memory allocations.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2148 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2149 char_u *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2150 v_throwpoint(char_u *oldval)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2151 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2152 if (oldval == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2153 return vimvars[VV_THROWPOINT].vv_str;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2154
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2155 vimvars[VV_THROWPOINT].vv_str = oldval;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2156 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2157 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2158
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2159 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2160 * Set v:cmdarg.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2161 * If "eap" != NULL, use "eap" to generate the value and return the old value.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2162 * If "oldarg" != NULL, restore the value to "oldarg" and return NULL.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2163 * Must always be called in pairs!
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2164 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2165 char_u *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2166 set_cmdarg(exarg_T *eap, char_u *oldarg)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2167 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2168 char_u *oldval;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2169 char_u *newval;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2170 unsigned len;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2171
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2172 oldval = vimvars[VV_CMDARG].vv_str;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2173 if (eap == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2174 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2175 vim_free(oldval);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2176 vimvars[VV_CMDARG].vv_str = oldarg;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2177 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2178 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2179
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2180 if (eap->force_bin == FORCE_BIN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2181 len = 6;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2182 else if (eap->force_bin == FORCE_NOBIN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2183 len = 8;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2184 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2185 len = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2186
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2187 if (eap->read_edit)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2188 len += 7;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2189
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2190 if (eap->force_ff != 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2191 len += 10; // " ++ff=unix"
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2192 if (eap->force_enc != 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2193 len += (unsigned)STRLEN(eap->cmd + eap->force_enc) + 7;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2194 if (eap->bad_char != 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2195 len += 7 + 4; // " ++bad=" + "keep" or "drop"
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2196
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2197 newval = alloc(len + 1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2198 if (newval == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2199 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2200
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2201 if (eap->force_bin == FORCE_BIN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2202 sprintf((char *)newval, " ++bin");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2203 else if (eap->force_bin == FORCE_NOBIN)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2204 sprintf((char *)newval, " ++nobin");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2205 else
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2206 *newval = NUL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2207
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2208 if (eap->read_edit)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2209 STRCAT(newval, " ++edit");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2210
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2211 if (eap->force_ff != 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2212 sprintf((char *)newval + STRLEN(newval), " ++ff=%s",
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2213 eap->force_ff == 'u' ? "unix"
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2214 : eap->force_ff == 'd' ? "dos"
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2215 : "mac");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2216 if (eap->force_enc != 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2217 sprintf((char *)newval + STRLEN(newval), " ++enc=%s",
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2218 eap->cmd + eap->force_enc);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2219 if (eap->bad_char == BAD_KEEP)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2220 STRCPY(newval + STRLEN(newval), " ++bad=keep");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2221 else if (eap->bad_char == BAD_DROP)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2222 STRCPY(newval + STRLEN(newval), " ++bad=drop");
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2223 else if (eap->bad_char != 0)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2224 sprintf((char *)newval + STRLEN(newval), " ++bad=%c", eap->bad_char);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2225 vimvars[VV_CMDARG].vv_str = newval;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2226 return oldval;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2227 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2228
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2229 /*
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 * Get the value of internal variable "name".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 * Return OK or FAIL. If OK is returned "rettv" must be cleared.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 get_var_tv(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 char_u *name,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 int len, // length of "name"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 typval_T *rettv, // NULL when only checking existence
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 dictitem_T **dip, // non-NULL when typval's dict item is needed
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 int verbose, // may give error message
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 int no_autoload) // do not use script autoloading
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 int ret = OK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 typval_T *tv = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 dictitem_T *v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 int cc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 // truncate the name, so that we can use strcmp()
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 cc = name[len];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 name[len] = NUL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 // Check for user-defined variables.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 v = find_var(name, NULL, no_autoload);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 if (v != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 tv = &v->di_tv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 if (dip != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 *dip = v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 if (tv == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 if (rettv != NULL && verbose)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 semsg(_(e_undefvar), name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 ret = FAIL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266 else if (rettv != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 copy_tv(tv, rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 name[len] = cc;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 return ret;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 /*
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2275 * Check if variable "name[len]" is a local variable or an argument.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2276 * If so, "*eval_lavars_used" is set to TRUE.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2277 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2278 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2279 check_vars(char_u *name, int len)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2280 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2281 int cc;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2282 char_u *varname;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2283 hashtab_T *ht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2284
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2285 if (eval_lavars_used == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2286 return;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2287
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2288 // truncate the name, so that we can use strcmp()
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2289 cc = name[len];
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2290 name[len] = NUL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2291
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2292 ht = find_var_ht(name, &varname);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2293 if (ht == get_funccal_local_ht() || ht == get_funccal_args_ht())
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2294 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2295 if (find_var(name, NULL, TRUE) != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2296 *eval_lavars_used = TRUE;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2297 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2298
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2299 name[len] = cc;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2300 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2301
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2302 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2303 * Find variable "name" in the list of variables.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2304 * Return a pointer to it if found, NULL if not found.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2305 * Careful: "a:0" variables don't have a name.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2306 * When "htp" is not NULL we are writing to the variable, set "htp" to the
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2307 * hashtab_T used.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2308 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2309 dictitem_T *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2310 find_var(char_u *name, hashtab_T **htp, int no_autoload)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2311 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2312 char_u *varname;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2313 hashtab_T *ht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2314 dictitem_T *ret = NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2315
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2316 ht = find_var_ht(name, &varname);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2317 if (htp != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2318 *htp = ht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2319 if (ht == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2320 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2321 ret = find_var_in_ht(ht, *name, varname, no_autoload || htp != NULL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2322 if (ret != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2323 return ret;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2324
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
2325 // Search in parent scope for lambda
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2326 return find_var_in_scoped_ht(name, no_autoload || htp != NULL);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2327 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2328
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2329 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2330 * Find variable "varname" in hashtab "ht" with name "htname".
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2331 * Returns NULL if not found.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2332 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2333 dictitem_T *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2334 find_var_in_ht(
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2335 hashtab_T *ht,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2336 int htname,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2337 char_u *varname,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2338 int no_autoload)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2339 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2340 hashitem_T *hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2341
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2342 if (*varname == NUL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2343 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2344 // Must be something like "s:", otherwise "ht" would be NULL.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2345 switch (htname)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2346 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2347 case 's': return &SCRIPT_SV(current_sctx.sc_sid)->sv_var;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2348 case 'g': return &globvars_var;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2349 case 'v': return &vimvars_var;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2350 case 'b': return &curbuf->b_bufvar;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2351 case 'w': return &curwin->w_winvar;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2352 case 't': return &curtab->tp_winvar;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2353 case 'l': return get_funccal_local_var();
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2354 case 'a': return get_funccal_args_var();
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2355 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2356 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2357 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2358
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2359 hi = hash_find(ht, varname);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2360 if (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2361 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2362 // For global variables we may try auto-loading the script. If it
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2363 // worked find the variable again. Don't auto-load a script if it was
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2364 // loaded already, otherwise it would be loaded every time when
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2365 // checking if a function name is a Funcref variable.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2366 if (ht == &globvarht && !no_autoload)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2367 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2368 // Note: script_autoload() may make "hi" invalid. It must either
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2369 // be obtained again or not used.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2370 if (!script_autoload(varname, FALSE) || aborting())
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2371 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2372 hi = hash_find(ht, varname);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2373 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2374 if (HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2375 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2376 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2377 return HI2DI(hi);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2378 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2379
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2380 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2381 * Find the hashtab used for a variable name.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2382 * Return NULL if the name is not valid.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2383 * Set "varname" to the start of name without ':'.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2384 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2385 hashtab_T *
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2386 find_var_ht(char_u *name, char_u **varname)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2387 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2388 hashitem_T *hi;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2389 hashtab_T *ht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2390
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2391 if (name[0] == NUL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2392 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2393 if (name[1] != ':')
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2394 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2395 // The name must not start with a colon or #.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2396 if (name[0] == ':' || name[0] == AUTOLOAD_CHAR)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2397 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2398 *varname = name;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2399
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2400 // "version" is "v:version" in all scopes if scriptversion < 3.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2401 // Same for a few other variables marked with VV_COMPAT.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2402 if (current_sctx.sc_version < 3)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2403 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2404 hi = hash_find(&compat_hashtab, name);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2405 if (!HASHITEM_EMPTY(hi))
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2406 return &compat_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2407 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2408
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2409 ht = get_funccal_local_ht();
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2410 if (ht == NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2411 return &globvarht; // global variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2412 return ht; // local variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2413 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2414 *varname = name + 2;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2415 if (*name == 'g') // global variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2416 return &globvarht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2417 // There must be no ':' or '#' in the rest of the name, unless g: is used
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2418 if (vim_strchr(name + 2, ':') != NULL
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2419 || vim_strchr(name + 2, AUTOLOAD_CHAR) != NULL)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2420 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2421 if (*name == 'b') // buffer variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2422 return &curbuf->b_vars->dv_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2423 if (*name == 'w') // window variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2424 return &curwin->w_vars->dv_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2425 if (*name == 't') // tab page variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2426 return &curtab->tp_vars->dv_hashtab;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2427 if (*name == 'v') // v: variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2428 return &vimvarht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2429 if (*name == 'a') // a: function argument
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2430 return get_funccal_args_ht();
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2431 if (*name == 'l') // l: local function variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2432 return get_funccal_local_ht();
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2433 if (*name == 's' // script variable
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2434 && current_sctx.sc_sid > 0
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2435 && current_sctx.sc_sid <= ga_scripts.ga_len)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2436 return &SCRIPT_VARS(current_sctx.sc_sid);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2437 return NULL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2438 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2439
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2440 /*
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 * Get the string value of a (global/local) variable.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 * Note: see tv_get_string() for how long the pointer remains valid.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 * Returns NULL when it doesn't exist.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 char_u *
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 get_var_value(char_u *name)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 dictitem_T *v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 v = find_var(name, NULL, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 if (v == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 return NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 return tv_get_string(&v->di_tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 /*
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2457 * Allocate a new hashtab for a sourced script. It will be used while
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2458 * sourcing this script and when executing functions defined in the script.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2459 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2460 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2461 new_script_vars(scid_T id)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2462 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2463 int i;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2464 hashtab_T *ht;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2465 scriptvar_T *sv;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2466
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2467 if (ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len)) == OK)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2468 {
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
2469 // Re-allocating ga_data means that an ht_array pointing to
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
2470 // ht_smallarray becomes invalid. We can recognize this: ht_mask is
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
2471 // at its init value. Also reset "v_dict", it's always the same.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2472 for (i = 1; i <= ga_scripts.ga_len; ++i)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2473 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2474 ht = &SCRIPT_VARS(i);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2475 if (ht->ht_mask == HT_INIT_SIZE - 1)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2476 ht->ht_array = ht->ht_smallarray;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2477 sv = SCRIPT_SV(i);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2478 sv->sv_var.di_tv.vval.v_dict = &sv->sv_dict;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2479 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2480
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2481 while (ga_scripts.ga_len < id)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2482 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2483 sv = SCRIPT_SV(ga_scripts.ga_len + 1) =
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2484 ALLOC_CLEAR_ONE(scriptvar_T);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2485 init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2486 ++ga_scripts.ga_len;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2487 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2488 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2489 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2490
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2491 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2492 * Initialize dictionary "dict" as a scope and set variable "dict_var" to
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2493 * point to it.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2494 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2495 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2496 init_var_dict(dict_T *dict, dictitem_T *dict_var, int scope)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2497 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2498 hash_init(&dict->dv_hashtab);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2499 dict->dv_lock = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2500 dict->dv_scope = scope;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2501 dict->dv_refcount = DO_NOT_FREE_CNT;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2502 dict->dv_copyID = 0;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2503 dict_var->di_tv.vval.v_dict = dict;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2504 dict_var->di_tv.v_type = VAR_DICT;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2505 dict_var->di_tv.v_lock = VAR_FIXED;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2506 dict_var->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2507 dict_var->di_key[0] = NUL;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2508 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2509
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2510 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2511 * Unreference a dictionary initialized by init_var_dict().
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2512 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2513 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2514 unref_var_dict(dict_T *dict)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2515 {
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
2516 // Now the dict needs to be freed if no one else is using it, go back to
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
2517 // normal reference counting.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2518 dict->dv_refcount -= DO_NOT_FREE_CNT - 1;
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2519 dict_unref(dict);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2520 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2521
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2522 /*
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 * Clean up a list of internal variables.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 * Frees all allocated variables and the value they contain.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 * Clears hashtab "ht", does not free it.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 vars_clear(hashtab_T *ht)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 vars_clear_ext(ht, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 * Like vars_clear(), but only free the value if "free_val" is TRUE.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 vars_clear_ext(hashtab_T *ht, int free_val)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 int todo;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540 hashitem_T *hi;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 dictitem_T *v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 hash_lock(ht);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 todo = (int)ht->ht_used;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 for (hi = ht->ht_array; todo > 0; ++hi)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 if (!HASHITEM_EMPTY(hi))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 --todo;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 // Free the variable. Don't remove it from the hashtab,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 // ht_array might change then. hash_clear() takes care of it
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 // later.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 v = HI2DI(hi);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 if (free_val)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 clear_tv(&v->di_tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 if (v->di_flags & DI_FLAGS_ALLOC)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 vim_free(v);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 hash_clear(ht);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 ht->ht_used = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 * Delete a variable from hashtab "ht" at item "hi".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 * Clear the variable value and free the dictitem.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 */
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
2569 static void
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 delete_var(hashtab_T *ht, hashitem_T *hi)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 dictitem_T *di = HI2DI(hi);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 hash_remove(ht, hi);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 clear_tv(&di->di_tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 vim_free(di);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 * List the value of one internal variable.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 list_one_var(dictitem_T *v, char *prefix, int *first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 char_u *tofree;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 char_u *s;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 char_u numbuf[NUMBUFLEN];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 s = echo_string(&v->di_tv, &tofree, numbuf, get_copyID());
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 list_one_var_a(prefix, v->di_key, v->di_tv.v_type,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 s == NULL ? (char_u *)"" : s, first);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 vim_free(tofree);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2596 list_one_var_a(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 char *prefix,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 char_u *name,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599 int type,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 char_u *string,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 int *first) // when TRUE clear rest of screen and set to FALSE
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 // don't use msg() or msg_attr() to avoid overwriting "v:statusmsg"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 msg_start();
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 msg_puts(prefix);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 if (name != NULL) // "a:" vars don't have a name stored
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 msg_puts((char *)name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608 msg_putchar(' ');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 msg_advance(22);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 if (type == VAR_NUMBER)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 msg_putchar('#');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 else if (type == VAR_FUNC || type == VAR_PARTIAL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 msg_putchar('*');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 else if (type == VAR_LIST)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 msg_putchar('[');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 if (*string == '[')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2618 ++string;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2620 else if (type == VAR_DICT)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 msg_putchar('{');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2623 if (*string == '{')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 ++string;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 msg_putchar(' ');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629 msg_outtrans(string);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2630
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2631 if (type == VAR_FUNC || type == VAR_PARTIAL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632 msg_puts("()");
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 if (*first)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635 msg_clr_eos();
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2636 *first = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2637 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2640 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2641 * Set variable "name" to value in "tv".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2642 * If the variable already exists, the value is updated.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2643 * Otherwise the variable is created.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2644 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 set_var(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 char_u *name,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 typval_T *tv,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2649 int copy) // make copy of value in "tv"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2651 set_var_const(name, tv, copy, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2653
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2655 * Set variable "name" to value in "tv".
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2656 * If the variable already exists and "is_const" is FALSE the value is updated.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2657 * Otherwise the variable is created.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2659 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2660 set_var_const(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2661 char_u *name,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2662 typval_T *tv,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2663 int copy, // make copy of value in "tv"
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2664 int is_const) // disallow to modify existing variable
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2666 dictitem_T *v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2667 char_u *varname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 hashtab_T *ht;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2669
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2670 ht = find_var_ht(name, &varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2671 if (ht == NULL || *varname == NUL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2672 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673 semsg(_(e_illvar), name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2674 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2675 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676 v = find_var_in_ht(ht, 0, varname, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2677
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2678 // Search in parent scope which is possible to reference from lambda
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2679 if (v == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2680 v = find_var_in_scoped_ht(name, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2682 if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2683 && var_check_func_name(name, v == NULL))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 if (v != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2687 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2688 if (is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2689 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 emsg(_(e_cannot_mod));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2692 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2693
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2694 // existing variable, need to clear the value
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2695 if (var_check_ro(v->di_flags, name, FALSE)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2696 || var_check_lock(v->di_tv.v_lock, name, FALSE))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2699 // Handle setting internal v: variables separately where needed to
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 // prevent changing the type.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2701 if (ht == &vimvarht)
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2702 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 if (v->di_tv.v_type == VAR_STRING)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2704 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705 VIM_CLEAR(v->di_tv.vval.v_string);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2706 if (copy || tv->v_type != VAR_STRING)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2708 char_u *val = tv_get_string(tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2709
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2710 // Careful: when assigning to v:errmsg and tv_get_string()
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 // causes an error message the variable will alrady be set.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 if (v->di_tv.vval.v_string == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2713 v->di_tv.vval.v_string = vim_strsave(val);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 // Take over the string to avoid an extra alloc/free.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718 v->di_tv.vval.v_string = tv->vval.v_string;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 tv->vval.v_string = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723 else if (v->di_tv.v_type == VAR_NUMBER)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 v->di_tv.vval.v_number = tv_get_number(tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726 if (STRCMP(varname, "searchforward") == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727 set_search_direction(v->di_tv.vval.v_number ? '/' : '?');
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 #ifdef FEAT_SEARCH_EXTRA
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2729 else if (STRCMP(varname, "hlsearch") == 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2730 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2731 no_hlsearch = !v->di_tv.vval.v_number;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 redraw_all_later(SOME_VALID);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2734 #endif
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2737 else if (v->di_tv.v_type != tv->v_type)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 semsg(_("E963: setting %s to value with wrong type"), name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2742 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744 clear_tv(&v->di_tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746 else // add a new variable
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748 // Can't add "v:" or "a:" variable.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
2749 if (ht == &vimvarht || ht == get_funccal_args_ht())
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2751 semsg(_(e_illvar), name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2752 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 // Make sure the variable name is valid.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 if (!valid_varname(varname))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2758
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 v = alloc(sizeof(dictitem_T) + STRLEN(varname));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 if (v == NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2762 STRCPY(v->di_key, varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763 if (hash_add(ht, DI2HIKEY(v)) == FAIL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 vim_free(v);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2767 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 v->di_flags = DI_FLAGS_ALLOC;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 if (is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770 v->di_flags |= DI_FLAGS_LOCK;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2774 copy_tv(tv, &v->di_tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 v->di_tv = *tv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778 v->di_tv.v_lock = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2779 init_tv(tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2782 if (is_const)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 v->di_tv.v_lock |= VAR_LOCKED;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 * Return TRUE if di_flags "flags" indicates variable "name" is read-only.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 * Also give an error message.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 var_check_ro(int flags, char_u *name, int use_gettext)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2793 if (flags & DI_FLAGS_RO)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 semsg(_(e_readonlyvar), use_gettext ? (char_u *)_(name) : name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798 if ((flags & DI_FLAGS_RO_SBX) && sandbox)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2800 semsg(_(e_readonlysbx), use_gettext ? (char_u *)_(name) : name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2803 return FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2804 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2805
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807 * Return TRUE if di_flags "flags" indicates variable "name" is fixed.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808 * Also give an error message.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2809 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2810 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 var_check_fixed(int flags, char_u *name, int use_gettext)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 if (flags & DI_FLAGS_FIX)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 semsg(_("E795: Cannot delete variable %s"),
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816 use_gettext ? (char_u *)_(name) : name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 return FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 * Check if a funcref is assigned to a valid variable name.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 * Return TRUE and give an error if not.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 var_check_func_name(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 char_u *name, // points to start of variable name
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 int new_var) // TRUE when creating the variable
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 // Allow for w: b: s: and t:.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2832 if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2834 ? name[2] : name[0]))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836 semsg(_("E704: Funcref variable name must start with a capital: %s"),
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837 name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840 // Don't allow hiding a function. When "v" is not NULL we might be
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841 // assigning another function to the same var, the type is checked
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2842 // below.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 if (new_var && function_exists(name, FALSE))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 semsg(_("E705: Variable name conflicts with existing function: %s"),
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2846 name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 return FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2853 * Return TRUE if "flags" indicates variable "name" is locked (immutable).
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854 * Also give an error message, using "name" or _("name") when use_gettext is
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 * TRUE.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2857 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 var_check_lock(int lock, char_u *name, int use_gettext)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 if (lock & VAR_LOCKED)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 semsg(_("E741: Value is locked: %s"),
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863 name == NULL ? (char_u *)_("Unknown")
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 : use_gettext ? (char_u *)_(name)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 : name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 if (lock & VAR_FIXED)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 semsg(_("E742: Cannot change value of %s"),
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 name == NULL ? (char_u *)_("Unknown")
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2872 : use_gettext ? (char_u *)_(name)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2873 : name);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 return FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880 * Check if a variable name is valid.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 * Return FALSE and give an error if not.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2883 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 valid_varname(char_u *varname)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 char_u *p;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 for (p = varname; *p != NUL; ++p)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 && *p != AUTOLOAD_CHAR)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2891 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 semsg(_(e_illvar), varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 return FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 return TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2898 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 * getwinvar() and gettabwinvar()
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 getwinvar(
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2903 typval_T *argvars,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904 typval_T *rettv,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2905 int off) // 1 for gettabwinvar()
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 win_T *win;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 char_u *varname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909 dictitem_T *v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 tabpage_T *tp = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 int done = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2912 win_T *oldcurwin;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 tabpage_T *oldtabpage;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 int need_switch_win;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 if (off == 1)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 tp = curtab;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920 win = find_win_by_nr(&argvars[off], tp);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 varname = tv_get_string_chk(&argvars[off + 1]);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 ++emsg_off;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2924 rettv->v_type = VAR_STRING;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2925 rettv->vval.v_string = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2926
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927 if (win != NULL && varname != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2928 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 // Set curwin to be our win, temporarily. Also set the tabpage,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2930 // otherwise the window is not valid. Only do this when needed,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931 // autocommands get blocked.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2932 need_switch_win = !(tp == curtab && win == curwin);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 if (!need_switch_win
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2936 if (*varname == '&')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2937 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2938 if (varname[1] == NUL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2939 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2940 // get all window-local options in a dict
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 dict_T *opts = get_winbuf_options(FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 if (opts != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2945 rettv_dict_set(rettv, opts);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 done = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 else if (get_option_tv(&varname, rettv, 1) == OK)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950 // window-local-option
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951 done = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2952 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955 // Look up the variable.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956 // Let getwinvar({nr}, "") return the "w:" dictionary.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957 v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w',
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958 varname, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2959 if (v != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2960 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 copy_tv(&v->di_tv, rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2962 done = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967 if (need_switch_win)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 // restore previous notion of curwin
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 restore_win(oldcurwin, oldtabpage, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973 // use the default return value
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 copy_tv(&argvars[off + 2], rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 --emsg_off;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 * "setwinvar()" and "settabwinvar()" functions
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 static void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 win_T *win;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 win_T *save_curwin;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 tabpage_T *save_curtab;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2988 int need_switch_win;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 char_u *varname, *winvarname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 typval_T *varp;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2991 char_u nbuf[NUMBUFLEN];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 tabpage_T *tp = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2994 if (check_secure())
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 if (off == 1)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2998 tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2999 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 tp = curtab;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 win = find_win_by_nr(&argvars[off], tp);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3002 varname = tv_get_string_chk(&argvars[off + 1]);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 varp = &argvars[off + 2];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005 if (win != NULL && varname != NULL && varp != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3006 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3007 need_switch_win = !(tp == curtab && win == curwin);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008 if (!need_switch_win
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3009 || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3010 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3011 if (*varname == '&')
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3013 long numval;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3014 char_u *strval;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 int error = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017 ++varname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 numval = (long)tv_get_number_chk(varp, &error);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3019 strval = tv_get_string_buf_chk(varp, nbuf);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3020 if (!error && strval != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3021 set_option_value(varname, numval, strval, OPT_LOCAL);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3022 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3023 else
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3024 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3025 winvarname = alloc(STRLEN(varname) + 3);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3026 if (winvarname != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3027 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3028 STRCPY(winvarname, "w:");
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3029 STRCPY(winvarname + 2, varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3030 set_var(winvarname, varp, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3031 vim_free(winvarname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3032 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3033 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3034 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3035 if (need_switch_win)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3036 restore_win(save_curwin, save_curtab, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3037 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3038 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3039
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3040 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3041 * reset v:option_new, v:option_old, v:option_oldlocal, v:option_oldglobal,
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3042 * v:option_type, and v:option_command.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3043 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3044 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3045 reset_v_option_vars(void)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3046 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3047 set_vim_var_string(VV_OPTION_NEW, NULL, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3048 set_vim_var_string(VV_OPTION_OLD, NULL, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3049 set_vim_var_string(VV_OPTION_OLDLOCAL, NULL, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3050 set_vim_var_string(VV_OPTION_OLDGLOBAL, NULL, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3051 set_vim_var_string(VV_OPTION_TYPE, NULL, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3052 set_vim_var_string(VV_OPTION_COMMAND, NULL, -1);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3053 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3054
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3055 /*
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3056 * Add an assert error to v:errors.
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3057 */
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3058 void
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3059 assert_error(garray_T *gap)
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3060 {
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3061 struct vimvar *vp = &vimvars[VV_ERRORS];
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3062
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3063 if (vp->vv_type != VAR_LIST || vimvars[VV_ERRORS].vv_list == NULL)
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3064 // Make sure v:errors is a list.
17885
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3065 set_vim_var_list(VV_ERRORS, list_alloc());
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3066 list_append_string(vimvars[VV_ERRORS].vv_list, gap->ga_data, gap->ga_len);
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3067 }
5e2d8840da11 patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents: 17873
diff changeset
3068
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3069 int
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3070 var_exists(char_u *var)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3071 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3072 char_u *name;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3073 char_u *tofree;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3074 typval_T tv;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3075 int len = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3076 int n = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3077
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3078 // get_name_len() takes care of expanding curly braces
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3079 name = var;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3080 len = get_name_len(&var, &tofree, TRUE, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081 if (len > 0)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3083 if (tofree != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084 name = tofree;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 n = (get_var_tv(name, len, &tv, NULL, FALSE, TRUE) == OK);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 if (n)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3088 // handle d.key, l[idx], f(expr)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3089 n = (handle_subscript(&var, &tv, TRUE, FALSE, name, &name) == OK);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3090 if (n)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3091 clear_tv(&tv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3092 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 if (*var != NUL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 n = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3097 vim_free(tofree);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 return n;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3099 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3101 static lval_T *redir_lval = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3102 #define EVALCMD_BUSY (redir_lval == (lval_T *)&redir_lval)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3103 static garray_T redir_ga; // only valid when redir_lval is not NULL
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3104 static char_u *redir_endp = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3105 static char_u *redir_varname = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3106
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3107 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3108 * Start recording command output to a variable
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3109 * When "append" is TRUE append to an existing variable.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3110 * Returns OK if successfully completed the setup. FAIL otherwise.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3111 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3112 int
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3113 var_redir_start(char_u *name, int append)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3114 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3115 int save_emsg;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3116 int err;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3117 typval_T tv;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3118
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3119 // Catch a bad name early.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3120 if (!eval_isnamec1(*name))
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3121 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3122 emsg(_(e_invarg));
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3123 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3124 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3125
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3126 // Make a copy of the name, it is used in redir_lval until redir ends.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3127 redir_varname = vim_strsave(name);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3128 if (redir_varname == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3129 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3130
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3131 redir_lval = ALLOC_CLEAR_ONE(lval_T);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3132 if (redir_lval == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3133 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3134 var_redir_stop();
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3135 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3136 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3137
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3138 // The output is stored in growarray "redir_ga" until redirection ends.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3139 ga_init2(&redir_ga, (int)sizeof(char), 500);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3140
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3141 // Parse the variable name (can be a dict or list entry).
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3142 redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, 0,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3143 FNE_CHECK_START);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3144 if (redir_endp == NULL || redir_lval->ll_name == NULL || *redir_endp != NUL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3145 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3146 clear_lval(redir_lval);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3147 if (redir_endp != NULL && *redir_endp != NUL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3148 // Trailing characters are present after the variable name
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3149 emsg(_(e_trailing));
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3150 else
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3151 emsg(_(e_invarg));
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3152 redir_endp = NULL; // don't store a value, only cleanup
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3153 var_redir_stop();
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3154 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3155 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3156
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3157 // check if we can write to the variable: set it to or append an empty
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3158 // string
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3159 save_emsg = did_emsg;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3160 did_emsg = FALSE;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3161 tv.v_type = VAR_STRING;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3162 tv.vval.v_string = (char_u *)"";
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3163 if (append)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3164 set_var_lval(redir_lval, redir_endp, &tv, TRUE, FALSE, (char_u *)".");
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3165 else
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3166 set_var_lval(redir_lval, redir_endp, &tv, TRUE, FALSE, (char_u *)"=");
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3167 clear_lval(redir_lval);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3168 err = did_emsg;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3169 did_emsg |= save_emsg;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3170 if (err)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3171 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3172 redir_endp = NULL; // don't store a value, only cleanup
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3173 var_redir_stop();
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3174 return FAIL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3175 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3176
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3177 return OK;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3178 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3179
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3180 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3181 * Append "value[value_len]" to the variable set by var_redir_start().
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3182 * The actual appending is postponed until redirection ends, because the value
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3183 * appended may in fact be the string we write to, changing it may cause freed
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3184 * memory to be used:
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3185 * :redir => foo
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3186 * :let foo
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3187 * :redir END
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3188 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3189 void
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3190 var_redir_str(char_u *value, int value_len)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3191 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3192 int len;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3193
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3194 if (redir_lval == NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3195 return;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3196
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3197 if (value_len == -1)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3198 len = (int)STRLEN(value); // Append the entire string
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3199 else
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3200 len = value_len; // Append only "value_len" characters
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3201
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3202 if (ga_grow(&redir_ga, len) == OK)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3203 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3204 mch_memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3205 redir_ga.ga_len += len;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3206 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3207 else
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3208 var_redir_stop();
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3209 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3210
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3211 /*
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3212 * Stop redirecting command output to a variable.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3213 * Frees the allocated memory.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3214 */
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3215 void
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3216 var_redir_stop(void)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3217 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3218 typval_T tv;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3219
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3220 if (EVALCMD_BUSY)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3221 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3222 redir_lval = NULL;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3223 return;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3224 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3225
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3226 if (redir_lval != NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3227 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3228 // If there was no error: assign the text to the variable.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3229 if (redir_endp != NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3230 {
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3231 ga_append(&redir_ga, NUL); // Append the trailing NUL.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3232 tv.v_type = VAR_STRING;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3233 tv.vval.v_string = redir_ga.ga_data;
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3234 // Call get_lval() again, if it's inside a Dict or List it may
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3235 // have changed.
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3236 redir_endp = get_lval(redir_varname, NULL, redir_lval,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3237 FALSE, FALSE, 0, FNE_CHECK_START);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3238 if (redir_endp != NULL && redir_lval->ll_name != NULL)
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3239 set_var_lval(redir_lval, redir_endp, &tv, FALSE, FALSE,
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3240 (char_u *)".");
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3241 clear_lval(redir_lval);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3242 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3243
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3244 // free the collected output
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3245 VIM_CLEAR(redir_ga.ga_data);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3246
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3247 VIM_CLEAR(redir_lval);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3248 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3249 VIM_CLEAR(redir_varname);
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3250 }
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17893
diff changeset
3251
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3252 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3253 * "gettabvar()" function
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3254 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3255 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3256 f_gettabvar(typval_T *argvars, typval_T *rettv)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3257 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3258 win_T *oldcurwin;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3259 tabpage_T *tp, *oldtabpage;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3260 dictitem_T *v;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3261 char_u *varname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3262 int done = FALSE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3263
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3264 rettv->v_type = VAR_STRING;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3265 rettv->vval.v_string = NULL;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3266
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3267 varname = tv_get_string_chk(&argvars[1]);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3268 tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3269 if (tp != NULL && varname != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3270 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3271 // Set tp to be our tabpage, temporarily. Also set the window to the
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3272 // first window in the tabpage, otherwise the window is not valid.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3273 if (switch_win(&oldcurwin, &oldtabpage,
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3274 tp == curtab || tp->tp_firstwin == NULL ? firstwin
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3275 : tp->tp_firstwin, tp, TRUE) == OK)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3276 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3277 // look up the variable
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3278 // Let gettabvar({nr}, "") return the "t:" dictionary.
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3279 v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3280 if (v != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3281 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3282 copy_tv(&v->di_tv, rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3283 done = TRUE;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3284 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3285 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3286
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3287 // restore previous notion of curwin
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3288 restore_win(oldcurwin, oldtabpage, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3289 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3290
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3291 if (!done && argvars[2].v_type != VAR_UNKNOWN)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3292 copy_tv(&argvars[2], rettv);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3293 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3294
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3295 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3296 * "gettabwinvar()" function
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3297 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3298 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3299 f_gettabwinvar(typval_T *argvars, typval_T *rettv)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3300 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3301 getwinvar(argvars, rettv, 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3302 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3303
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3304 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3305 * "getwinvar()" function
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3306 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3307 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 f_getwinvar(typval_T *argvars, typval_T *rettv)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310 getwinvar(argvars, rettv, 0);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 /*
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3314 * "getbufvar()" function
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3315 */
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3316 void
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3317 f_getbufvar(typval_T *argvars, typval_T *rettv)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3318 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3319 buf_T *buf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3320 buf_T *save_curbuf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3321 char_u *varname;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3322 dictitem_T *v;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3323 int done = FALSE;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3324
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3325 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3326 varname = tv_get_string_chk(&argvars[1]);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3327 ++emsg_off;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3328 buf = tv_get_buf(&argvars[0], FALSE);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3329
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3330 rettv->v_type = VAR_STRING;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3331 rettv->vval.v_string = NULL;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3332
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3333 if (buf != NULL && varname != NULL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3334 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3335 // set curbuf to be our buf, temporarily
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3336 save_curbuf = curbuf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3337 curbuf = buf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3338
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3339 if (*varname == '&')
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3340 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3341 if (varname[1] == NUL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3342 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3343 // get all buffer-local options in a dict
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3344 dict_T *opts = get_winbuf_options(TRUE);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3345
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3346 if (opts != NULL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3347 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3348 rettv_dict_set(rettv, opts);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3349 done = TRUE;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3350 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3351 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3352 else if (get_option_tv(&varname, rettv, TRUE) == OK)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3353 // buffer-local-option
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3354 done = TRUE;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3355 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3356 else
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3357 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3358 // Look up the variable.
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3359 // Let getbufvar({nr}, "") return the "b:" dictionary.
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3360 v = find_var_in_ht(&curbuf->b_vars->dv_hashtab,
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3361 'b', varname, FALSE);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3362 if (v != NULL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3363 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3364 copy_tv(&v->di_tv, rettv);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3365 done = TRUE;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3366 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3367 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3368
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3369 // restore previous notion of curbuf
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3370 curbuf = save_curbuf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3371 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3372
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3373 if (!done && argvars[2].v_type != VAR_UNKNOWN)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3374 // use the default value
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3375 copy_tv(&argvars[2], rettv);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3376
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3377 --emsg_off;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3378 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3379
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3380 /*
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3381 * "settabvar()" function
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3382 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3383 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3384 f_settabvar(typval_T *argvars, typval_T *rettv)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3385 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3386 tabpage_T *save_curtab;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3387 tabpage_T *tp;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3388 char_u *varname, *tabvarname;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3389 typval_T *varp;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3390
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 rettv->vval.v_number = 0;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3392
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3393 if (check_secure())
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 return;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396 tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397 varname = tv_get_string_chk(&argvars[1]);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 varp = &argvars[2];
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3399
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 if (varname != NULL && varp != NULL && tp != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3401 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3402 save_curtab = curtab;
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3403 goto_tabpage_tp(tp, FALSE, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3404
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3405 tabvarname = alloc(STRLEN(varname) + 3);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3406 if (tabvarname != NULL)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3407 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3408 STRCPY(tabvarname, "t:");
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3409 STRCPY(tabvarname + 2, varname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3410 set_var(tabvarname, varp, TRUE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3411 vim_free(tabvarname);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3412 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3413
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 // Restore current tabpage
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 if (valid_tabpage(save_curtab))
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3416 goto_tabpage_tp(save_curtab, FALSE, FALSE);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3417 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3418 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3419
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3420 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3421 * "settabwinvar()" function
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3422 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3423 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3424 f_settabwinvar(typval_T *argvars, typval_T *rettv)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3425 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3426 setwinvar(argvars, rettv, 1);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3427 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3428
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3429 /*
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3430 * "setwinvar()" function
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 */
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3432 void
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3433 f_setwinvar(typval_T *argvars, typval_T *rettv)
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3434 {
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3435 setwinvar(argvars, rettv, 0);
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3436 }
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3437
17893
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3438 /*
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3439 * "setbufvar()" function
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3440 */
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3441 void
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3442 f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3443 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3444 buf_T *buf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3445 char_u *varname, *bufvarname;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3446 typval_T *varp;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3447 char_u nbuf[NUMBUFLEN];
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3448
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3449 if (check_secure())
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3450 return;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3451 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3452 varname = tv_get_string_chk(&argvars[1]);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3453 buf = tv_get_buf(&argvars[0], FALSE);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3454 varp = &argvars[2];
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3455
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3456 if (buf != NULL && varname != NULL && varp != NULL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3457 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3458 if (*varname == '&')
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3459 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3460 long numval;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3461 char_u *strval;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3462 int error = FALSE;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3463 aco_save_T aco;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3464
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3465 // set curbuf to be our buf, temporarily
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3466 aucmd_prepbuf(&aco, buf);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3467
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3468 ++varname;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3469 numval = (long)tv_get_number_chk(varp, &error);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3470 strval = tv_get_string_buf_chk(varp, nbuf);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3471 if (!error && strval != NULL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3472 set_option_value(varname, numval, strval, OPT_LOCAL);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3473
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3474 // reset notion of buffer
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3475 aucmd_restbuf(&aco);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3476 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3477 else
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3478 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3479 buf_T *save_curbuf = curbuf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3480
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3481 bufvarname = alloc(STRLEN(varname) + 3);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3482 if (bufvarname != NULL)
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3483 {
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3484 curbuf = buf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3485 STRCPY(bufvarname, "b:");
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3486 STRCPY(bufvarname + 2, varname);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3487 set_var(bufvarname, varp, TRUE);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3488 vim_free(bufvarname);
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3489 curbuf = save_curbuf;
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3490 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3491 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3492 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3493 }
e4d3b6c466d4 patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17887
diff changeset
3494
17986
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3495 /*
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3496 * Get a callback from "arg". It can be a Funcref or a function name.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3497 * When "arg" is zero return an empty string.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3498 * "cb_name" is not allocated.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3499 * "cb_name" is set to NULL for an invalid argument.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3500 */
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3501 callback_T
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3502 get_callback(typval_T *arg)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3503 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3504 callback_T res;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3505
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3506 res.cb_free_name = FALSE;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3507 if (arg->v_type == VAR_PARTIAL && arg->vval.v_partial != NULL)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3508 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3509 res.cb_partial = arg->vval.v_partial;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3510 ++res.cb_partial->pt_refcount;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3511 res.cb_name = partial_name(res.cb_partial);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3512 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3513 else
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3514 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3515 res.cb_partial = NULL;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3516 if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3517 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3518 // Note that we don't make a copy of the string.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3519 res.cb_name = arg->vval.v_string;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3520 func_ref(res.cb_name);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3521 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3522 else if (arg->v_type == VAR_NUMBER && arg->vval.v_number == 0)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3523 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3524 res.cb_name = (char_u *)"";
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3525 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3526 else
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3527 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3528 emsg(_("E921: Invalid callback argument"));
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3529 res.cb_name = NULL;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3530 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3531 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3532 return res;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3533 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3534
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3535 /*
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3536 * Copy a callback into a typval_T.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3537 */
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3538 void
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3539 put_callback(callback_T *cb, typval_T *tv)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3540 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3541 if (cb->cb_partial != NULL)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3542 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3543 tv->v_type = VAR_PARTIAL;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3544 tv->vval.v_partial = cb->cb_partial;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3545 ++tv->vval.v_partial->pt_refcount;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3546 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3547 else
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3548 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3549 tv->v_type = VAR_FUNC;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3550 tv->vval.v_string = vim_strsave(cb->cb_name);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3551 func_ref(cb->cb_name);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3552 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3553 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3554
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3555 /*
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3556 * Make a copy of "src" into "dest", allocating the function name if needed,
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3557 * without incrementing the refcount.
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3558 */
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3559 void
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3560 set_callback(callback_T *dest, callback_T *src)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3561 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3562 if (src->cb_partial == NULL)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3563 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3564 // just a function name, make a copy
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3565 dest->cb_name = vim_strsave(src->cb_name);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3566 dest->cb_free_name = TRUE;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3567 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3568 else
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3569 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3570 // cb_name is a pointer into cb_partial
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3571 dest->cb_name = src->cb_name;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3572 dest->cb_free_name = FALSE;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3573 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3574 dest->cb_partial = src->cb_partial;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3575 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3576
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3577 /*
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3578 * Unref/free "callback" returned by get_callback() or set_callback().
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3579 */
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3580 void
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3581 free_callback(callback_T *callback)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3582 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3583 if (callback->cb_partial != NULL)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3584 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3585 partial_unref(callback->cb_partial);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3586 callback->cb_partial = NULL;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3587 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3588 else if (callback->cb_name != NULL)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3589 func_unref(callback->cb_name);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3590 if (callback->cb_free_name)
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3591 {
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3592 vim_free(callback->cb_name);
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3593 callback->cb_free_name = FALSE;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3594 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3595 callback->cb_name = NULL;
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3596 }
5c8906f653f5 patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents: 17944
diff changeset
3597
17873
d50a5faa75bd patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3598 #endif // FEAT_EVAL