Mercurial > vim
annotate src/evalvars.c @ 22074:923f618adb59
Added tag v8.2.1586 for changeset 28b302ccfe217f22bed590436a401006a57faa6c
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 04 Sep 2020 14:45:06 +0200 |
parents | ee967cdcf749 |
children | 7899b4e2880c |
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 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
18 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
|
19 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
|
20 #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
|
21 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
22 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
23 * 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
|
24 * 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
|
25 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
26 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
|
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 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
29 * 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
|
30 * 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
|
31 * 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
|
32 * 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
|
33 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
34 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
35 // 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
|
36 #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
|
37 #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
|
38 #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
|
39 |
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_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
|
41 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
42 typedef struct vimvar vimvar_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
43 |
17885
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}, |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
121 {VV_NAME("false", VAR_BOOL), VV_RO}, |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
122 {VV_NAME("true", VAR_BOOL), VV_RO}, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
123 {VV_NAME("none", VAR_SPECIAL), 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
|
124 {VV_NAME("null", VAR_SPECIAL), VV_RO}, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
125 {VV_NAME("numbersize", VAR_NUMBER), 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
|
126 {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
|
127 {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
|
128 {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
|
129 {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
|
130 {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
|
131 {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
|
132 {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
|
133 {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
|
134 {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
|
135 {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
|
136 {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
|
137 {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
|
138 {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
|
139 {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
|
140 {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
|
141 {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
|
142 {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
|
143 {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
|
144 {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
|
145 {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
|
146 {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
|
147 {VV_NAME("argv", VAR_LIST), VV_RO}, |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
148 {VV_NAME("collate", VAR_STRING), 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
|
149 }; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
150 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
151 // shorthand |
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_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
|
153 #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
|
154 #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
|
155 #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
|
156 #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
|
157 #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
|
158 #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
|
159 #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
|
160 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
161 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
|
162 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
|
163 #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
|
164 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
165 // 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
|
166 #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
|
167 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
173 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int flags, char_u *endchars, char_u *op); |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
174 static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
175 static int do_lock_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
176 static void item_lock(typval_T *tv, int deep, int lock, int check_refcount); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
182 * 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
|
183 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
184 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
185 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
|
186 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
187 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
|
188 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
|
189 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
194 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
195 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
|
196 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
197 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
|
198 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
|
199 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
200 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
|
201 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
|
202 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
209 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
|
210 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
211 // 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
|
212 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
|
213 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
|
214 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
|
215 // 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
|
216 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
|
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 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
|
219 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
|
220 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 set_vim_var_nr(VV_NULL, VVAL_NULL); |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
231 set_vim_var_nr(VV_NUMBERSIZE, sizeof(varnumber_T) * 8); |
17885
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 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 |
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_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
|
246 |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
247 // Default for v:register is not 0 but '"'. This is adjusted once the |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
248 // clipboard has been setup by calling reset_reg_var(). |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
249 set_reg_var(0); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
250 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
251 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
252 #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
|
253 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
254 * 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
|
255 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
256 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
257 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
|
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 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
|
260 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
|
261 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
262 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
|
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 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
|
265 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
|
266 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
|
267 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
|
268 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
269 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
|
270 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
|
271 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
272 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
277 // 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
|
278 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
|
279 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
280 // Script-local variables. Clear all the variables here. |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
281 // The scriptvar_T is cleared later in free_scriptnames(), because a |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
282 // variable in one script might hold a reference to the whole scope of |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
283 // another script. |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
284 for (i = 1; i <= script_items.ga_len; ++i) |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
285 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
|
286 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
287 #endif |
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 int |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
290 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
|
291 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
292 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
|
293 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
294 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
295 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
|
296 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
|
297 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
298 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
|
299 } |
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 int |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
302 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
|
303 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
304 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
|
305 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
|
306 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
307 for (i = 1; i <= script_items.ga_len; ++i) |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
308 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
|
309 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
310 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
|
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 |
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 * 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
|
315 * 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
|
316 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
317 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
318 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
|
319 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
320 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
|
321 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
|
322 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
323 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
|
324 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
|
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 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
|
327 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
|
328 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
329 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
|
330 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
|
331 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
332 } |
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 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
335 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
336 eval_charconvert( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 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
|
341 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
342 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
|
343 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 err = TRUE; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
355 if (err) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
356 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
357 return OK; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
358 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
359 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
360 # 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
|
361 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
362 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
|
363 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
364 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
|
365 |
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, fname, -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_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
|
368 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
|
369 err = TRUE; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
370 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
|
371 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
|
372 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
373 if (err) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
374 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
375 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
|
376 return FAIL; |
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 return OK; |
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 # endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
381 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
382 # 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
|
383 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
384 eval_diff( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
389 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
|
390 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 (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
|
395 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
|
396 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
|
397 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
|
398 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
399 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
400 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
401 eval_patch( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
406 int err; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
407 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
408 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
|
409 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
|
410 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
|
411 (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
|
412 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
|
413 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
|
414 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
|
415 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
416 # endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
417 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
418 #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
|
419 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
420 * 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
|
421 * 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
|
422 * 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
|
423 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
424 list_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
425 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
|
426 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 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
|
431 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
432 // 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
|
433 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
|
434 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
|
435 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
|
436 ++emsg_off; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
437 |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
438 if (eval1(&p, &rettv, &EVALARG_EVALUATE) == OK) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
439 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
440 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
|
441 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
|
442 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
443 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
|
444 } |
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 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
|
447 --emsg_off; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
448 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
|
449 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
|
450 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
451 return list; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
452 } |
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 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
455 * "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
|
456 * 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
|
457 * 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
|
458 * 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
|
459 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
460 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
461 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
|
462 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
463 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
|
464 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
465 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
|
466 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
|
467 return -1; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
468 *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
|
469 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
470 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
|
471 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
|
472 return -1; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
473 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
|
474 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
475 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
476 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
477 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
478 * 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
|
479 * 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
|
480 * 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
|
481 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
482 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
483 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
|
484 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
485 *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
|
486 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
|
487 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
|
488 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
|
489 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
490 |
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 * 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
|
493 * 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
|
494 * 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
|
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 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
|
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 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
|
500 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
501 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
|
502 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
|
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 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
|
505 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
|
506 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
|
507 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
508 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
|
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 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
511 |
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 * 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
|
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 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
|
516 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
|
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 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
|
519 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
520 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
521 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
522 * 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
|
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 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
|
525 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
|
526 { |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21955
diff
changeset
|
527 if (SCRIPT_ID_VALID(current_sctx.sc_sid)) |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
528 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
|
529 "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
|
530 } |
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 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 * 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
|
534 * 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
|
535 * cmd << {marker} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 * {line1} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 * {line2} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 * .... |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 * {marker} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 * 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
|
542 * 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
|
543 * indentation in the 'cmd' line) is stripped. |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
544 * |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
545 * When getting lines for an embedded script (e.g. python, lua, perl, ruby, |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
546 * tcl, mzscheme), script_get is set to TRUE. In this case, if the marker is |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
547 * missing, then '.' is accepted as a marker. |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
548 * |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 * 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
|
550 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
551 list_T * |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
552 heredoc_get(exarg_T *eap, char_u *cmd, int script_get) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 char_u *theline; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 char_u *marker; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 char_u *p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 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
|
559 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
|
560 char_u *text_indent = NULL; |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
561 char_u dot[] = "."; |
17873
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 if (eap->getline == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 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
|
566 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 // 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
|
570 cmd = skipwhite(cmd); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 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
|
572 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 cmd = skipwhite(cmd + 4); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 // 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
|
576 // 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
|
577 // 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
|
578 // 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
|
579 p = *eap->cmdlinep; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 while (VIM_ISWHITE(*p)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 p++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 marker_indent_len++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 text_indent_len = -1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 // 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
|
589 if (*cmd != NUL && *cmd != '"') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 marker = skipwhite(cmd); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 p = skiptowhite(marker); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 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
|
594 { |
21461
4dfd00f481fb
patch 8.2.1281: the "trailing characters" error can be hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
21447
diff
changeset
|
595 semsg(_(e_trailing_arg), p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 *p = NUL; |
20233
5f9c2c7d3d73
patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents:
20148
diff
changeset
|
599 if (!script_get && vim_islower(*marker)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 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
|
602 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 { |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
607 // When getting lines for an embedded script, if the marker is missing, |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
608 // accept '.' as the marker. |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
609 if (script_get) |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
610 marker = dot; |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
611 else |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
612 { |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
613 emsg(_("E172: Missing marker")); |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
614 return NULL; |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
615 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 } |
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 l = list_alloc(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 if (l == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 for (;;) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 int mi = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 int ti = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 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
|
628 if (theline == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 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
|
631 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 } |
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 // 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
|
635 // marker |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 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
|
637 && 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
|
638 mi = marker_indent_len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 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
|
640 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 vim_free(theline); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 } |
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 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
|
646 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 // 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
|
648 p = theline; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 text_indent_len = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 while (VIM_ISWHITE(*p)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 p++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 text_indent_len++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 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
|
656 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 // 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
|
658 if (text_indent != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 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
|
660 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
|
661 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 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
|
664 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 vim_free(theline); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 vim_free(text_indent); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 return l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 } |
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 * ":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
|
674 * ":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
|
675 * ":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
|
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 [var1, var2] = expr" unpack list. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
684 * ":let var =<< ..." heredoc |
19524
4a6a412e4565
patch 8.2.0319: file missing in distribution, comments outdated
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
685 * ":let var: string" Vim9 declaration |
20536
8fa783f2c69c
patch 8.2.0822: Vim9: code left over from discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20530
diff
changeset
|
686 * |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 * ":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
|
688 * ":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
|
689 * ":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
|
690 * ":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
|
691 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 void |
20536
8fa783f2c69c
patch 8.2.0822: Vim9: code left over from discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20530
diff
changeset
|
693 ex_let(exarg_T *eap) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 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
|
696 char_u *expr = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 typval_T rettv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 int i; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 int var_count = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 int semicolon = 0; |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
701 char_u op[4]; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 char_u *argend; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 int first = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 int concat; |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
705 int has_assign; |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20326
diff
changeset
|
706 int flags = eap->cmdidx == CMD_const ? LET_IS_CONST : 0; |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
707 int vim9script = in_vim9script(); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
708 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
709 // detect Vim9 assignment without ":let" or ":const" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
710 if (eap->arg == eap->cmd) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
711 flags |= LET_NO_COMMAND; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
712 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
713 argend = skip_var_list(arg, TRUE, &var_count, &semicolon, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 if (argend == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 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
|
717 --argend; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 expr = skipwhite(argend); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 concat = expr[0] == '.' |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 && ((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
|
721 || (expr[1] == '.' && expr[2] == '=')); |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
722 has_assign = *expr == '=' || (vim_strchr((char_u *)"+-*/%", *expr) != NULL |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
723 && expr[1] == '='); |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
724 if (!has_assign && !concat) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 // ":let" without "=": list variables |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 if (*arg == '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 emsg(_(e_invarg)); |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
729 else if (expr[0] == '.' && expr[1] == '=') |
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
730 emsg(_("E985: .= is not supported with script version >= 2")); |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20103
diff
changeset
|
731 else if (!ends_excmd2(eap->cmd, arg)) |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
732 { |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
733 if (vim9script) |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
734 { |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
735 // Vim9 declaration ":let var: type" |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
736 arg = vim9_declare_scriptvar(eap, arg); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
737 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
738 else |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
739 { |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
740 // ":let var1 var2" - list values |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
741 arg = list_arg_vars(eap, arg, &first); |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
742 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
743 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 else if (!eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 // ":let" |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 list_glob_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 list_buf_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 list_win_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 list_tab_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 list_script_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 list_func_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 list_vim_vars(&first); |
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 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
|
756 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 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
|
758 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 // HERE document |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
762 l = heredoc_get(eap, expr + 3, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 if (l != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 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
|
766 if (!eap->skip) |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
767 { |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
768 op[0] = '='; |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
769 op[1] = NUL; |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
770 (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
771 flags, op); |
18348
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
772 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 } |
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 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
778 evalarg_T evalarg; |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
779 int len = 1; |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
780 |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
781 rettv.v_type = VAR_UNKNOWN; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
782 i = FAIL; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
783 if (has_assign || concat) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
785 op[0] = '='; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
786 op[1] = NUL; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
787 if (*expr != '=') |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 { |
21905
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
789 if (vim9script && (flags & LET_NO_COMMAND) == 0) |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
790 { |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
791 // +=, /=, etc. require an existing variable |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
792 semsg(_(e_cannot_use_operator_on_new_variable), eap->arg); |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
793 i = FAIL; |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
794 } |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
795 else if (vim_strchr((char_u *)"+-*/%.", *expr) != NULL) |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
796 { |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
797 op[0] = *expr; // +=, -=, *=, /=, %= or .= |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
798 ++len; |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
799 if (expr[0] == '.' && expr[1] == '.') // ..= |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
800 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
801 ++expr; |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
802 ++len; |
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
803 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
804 } |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
805 expr += 2; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
807 else |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
808 ++expr; |
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
809 |
21548
4e679db1c404
patch 8.2.1324: Vim9: line break after "=" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
810 if (vim9script && (!VIM_ISWHITE(*argend) |
4e679db1c404
patch 8.2.1324: Vim9: line break after "=" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
811 || !IS_WHITE_OR_NUL(*expr))) |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
812 { |
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
813 vim_strncpy(op, expr - len, len); |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21905
diff
changeset
|
814 semsg(_(e_white_space_required_before_and_after_str), op); |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
815 i = FAIL; |
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
816 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
817 |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
818 if (eap->skip) |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
819 ++emsg_skip; |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
820 CLEAR_FIELD(evalarg); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
821 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; |
21056
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
822 if (getline_equal(eap->getline, eap->cookie, getsourceline)) |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
823 { |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
824 evalarg.eval_getline = eap->getline; |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
825 evalarg.eval_cookie = eap->cookie; |
a7c202f5cbe9
patch 8.2.1079: Vim9: no line break allowed in a while loop
Bram Moolenaar <Bram@vim.org>
parents:
21050
diff
changeset
|
826 } |
21548
4e679db1c404
patch 8.2.1324: Vim9: line break after "=" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
827 expr = skipwhite_and_linebreak(expr, &evalarg); |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
828 i = eval0(expr, &rettv, eap, &evalarg); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
829 if (eap->skip) |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
830 --emsg_skip; |
21050
7a9daf73a724
patch 8.2.1076: Vim9: no line break allowed in :if expression
Bram Moolenaar <Bram@vim.org>
parents:
21040
diff
changeset
|
831 clear_evalarg(&evalarg, eap); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 if (eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 if (i != FAIL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
838 else if (i != FAIL) |
17873
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 (void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count, |
21447
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
841 flags, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 clear_tv(&rettv); |
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 * 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
|
849 * 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
|
850 * 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
|
851 * 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
|
852 * or concatenate. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 * Returns OK or 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 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 ex_let_vars( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 char_u *arg_start, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 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
|
860 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
|
861 int var_count, // from skip_var_list() |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
862 int flags, // LET_IS_CONST and/or LET_NO_COMMAND |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 char_u *op) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 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
|
866 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 int i; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 listitem_T *item; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 typval_T ltv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 if (*arg != '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 // ":let var = expr" or ":for var in list" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
874 if (ex_let_one(arg, tv, copy, flags, op, op) == NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 } |
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 // ":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
|
880 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
|
881 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 emsg(_(e_listreq)); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 return FAIL; |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 i = list_len(l); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 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
|
888 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 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
|
890 return FAIL; |
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 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
|
893 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 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
|
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 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
898 CHECK_LIST_MATERIALIZE(l); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 item = l->lv_first; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 while (*arg != ']') |
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 arg = skipwhite(arg + 1); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
903 arg = ex_let_one(arg, &item->li_tv, TRUE, flags, (char_u *)",;]", op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 item = item->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 if (arg == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 if (*arg == ';') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 // 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
|
912 // 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
|
913 l = list_alloc(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 if (l == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 while (item != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 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
|
919 item = item->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 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
|
923 ltv.v_lock = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 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
|
925 l->lv_refcount = 1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
927 arg = ex_let_one(skipwhite(arg + 1), <v, FALSE, flags, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 (char_u *)"]", op); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 clear_tv(<v); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 if (arg == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 else if (*arg != ',' && *arg != ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 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
|
937 return FAIL; |
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 * 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
|
946 * 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
|
947 * For "[var, var]" increment "*var_count" for each variable. |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
948 * for "[var, var; var]" set "semicolon" to 1. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
949 * If "silent" is TRUE do not give an "invalid argument" error message. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 * 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
|
951 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 skip_var_list( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 char_u *arg, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
955 int include_type, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 int *var_count, |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
957 int *semicolon, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
958 int silent) |
17873
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 char_u *p, *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 if (*arg == '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 // "[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
|
965 p = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 for (;;) |
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 p = skipwhite(p + 1); // skip whites after '[', ';' or ',' |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
969 s = skip_var_one(p, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 if (s == p) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
972 if (!silent) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
973 semsg(_(e_invarg2), p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 ++*var_count; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 p = skipwhite(s); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 if (*p == ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 else if (*p == ';') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 if (*semicolon == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 { |
19860
37c4779ca8f5
patch 8.2.0486: Vim9: some code and error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19834
diff
changeset
|
985 emsg(_("E452: Double ; in list of variables")); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 return NULL; |
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 *semicolon = 1; |
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 else if (*p != ',') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
992 if (!silent) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
993 semsg(_(e_invarg2), p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 return p + 1; |
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 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1000 return skip_var_one(arg, include_type); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 } |
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 * 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
|
1005 * l[idx]. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1006 * In Vim9 script also skip over ": type" if "include_type" is TRUE. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 */ |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1008 char_u * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1009 skip_var_one(char_u *arg, int include_type) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1011 char_u *end; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1012 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 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
|
1014 return arg + 2; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1015 end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
1017 if (include_type && in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1018 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1019 // "a: type" is declaring variable "a" with a type, not "a:". |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1020 if (end == arg + 2 && end[-1] == ':') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1021 --end; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1022 if (*end == ':') |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
1023 end = skip_type(skipwhite(end + 1), FALSE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1024 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1025 return end; |
17873
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 * 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
|
1030 * 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
|
1031 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 list_hashtable_vars( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 hashtab_T *ht, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 char *prefix, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 int empty, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 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 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 char_u buf[IOSIZE]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 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
|
1045 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
|
1046 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 --todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 di = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 // 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
|
1053 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
|
1054 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
|
1055 if (message_filtered(buf)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 continue; |
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 (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
|
1059 || 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
|
1060 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
|
1061 } |
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 * List global variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 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
|
1070 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 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
|
1072 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 |
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 * List buffer variables. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 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
|
1079 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 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
|
1081 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 * List window variables. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 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
|
1088 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 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
|
1090 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 |
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 * List tab page variables. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 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
|
1097 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 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
|
1099 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 |
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 * List variables in "arg". |
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 static char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 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
|
1106 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 int error = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 int len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 char_u *name_start; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 char_u *arg_subsc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 typval_T tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20103
diff
changeset
|
1115 while (!ends_excmd2(eap->cmd, arg) && !got_int) |
17873
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 if (error || eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 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
|
1120 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
|
1121 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 emsg_severe = TRUE; |
21461
4dfd00f481fb
patch 8.2.1281: the "trailing characters" error can be hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
21447
diff
changeset
|
1123 semsg(_(e_trailing_arg), arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 // 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
|
1130 name_start = name = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 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
|
1132 if (len <= 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 // 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
|
1135 // 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
|
1136 if (len < 0 && !aborting()) |
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 emsg_severe = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 semsg(_(e_invarg2), arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 error = TRUE; |
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 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
1146 arg = skipwhite(arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 if (tofree != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 name = tofree; |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
1149 if (eval_variable(name, len, &tv, NULL, TRUE, FALSE) == FAIL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 // 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
|
1154 arg_subsc = arg; |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1155 if (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, TRUE) |
21032
f80e822a310d
patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
1156 == FAIL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 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
|
1161 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 switch (*name) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 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
|
1171 default: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 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
|
1173 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 else |
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 char_u numbuf[NUMBUFLEN]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 char_u *tf; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 int c; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 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
|
1183 c = *arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 *arg = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 list_one_var_a("", |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 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
|
1187 tv.v_type, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 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
|
1189 first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 *arg = c; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 vim_free(tf); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 clear_tv(&tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 } |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 vim_free(tofree); |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 return arg; |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 * 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
|
1209 * 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
|
1210 * 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
|
1211 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 static char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 ex_let_one( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 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
|
1215 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
|
1216 int copy, // copy value from "tv" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1217 int flags, // LET_IS_CONST and/or LET_NO_COMMAND |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 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
|
1219 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
|
1220 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 int c1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 char_u *p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 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
|
1225 int len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 int opt_flags; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 char_u *tofree = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1229 if (in_vim9script() && (flags & LET_NO_COMMAND) == 0 |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1230 && vim_strchr((char_u *)"$@&", *arg) != NULL) |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1231 { |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1232 vim9_declare_error(arg); |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1233 return NULL; |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1234 } |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1235 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 // ":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
|
1237 if (*arg == '$') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1239 if (flags & LET_IS_CONST) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 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
|
1242 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 } |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1244 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 // 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
|
1246 ++arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 name = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 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
|
1249 if (len == 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 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
|
1251 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 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
|
1254 semsg(_(e_letwrong), op); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 else if (endchars != NULL |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 && 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
|
1257 emsg(_(e_letunexp)); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 else if (!check_secure()) |
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 c1 = name[len]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 name[len] = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 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
|
1263 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
|
1264 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 int mustfree = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 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
|
1267 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 if (s != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 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
|
1271 if (mustfree) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 vim_free(s); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 } |
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 if (p != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 { |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
1277 vim_setenv_ext(name, p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 arg_end = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 name[len] = c1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 vim_free(tofree); |
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 } |
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 // ":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
|
1287 // ":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
|
1288 // ":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
|
1289 else if (*arg == '&') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1291 if (flags & LET_IS_CONST) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1293 emsg(_(e_const_option)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 // 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
|
1297 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
|
1298 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
|
1299 && 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
|
1300 emsg(_(e_letunexp)); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 { |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1303 long n = 0; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 int opt_type; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 long numval; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 char_u *stringval = NULL; |
20148
fadb7f84beff
patch 8.2.0629: setting a boolean option to v:false does not work
Bram Moolenaar <Bram@vim.org>
parents:
20111
diff
changeset
|
1307 char_u *s = NULL; |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1308 int failed = FALSE; |
17873
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 c1 = *p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 *p = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1313 opt_type = get_option_value(arg, &numval, &stringval, opt_flags); |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1314 if ((opt_type == 1 || opt_type == -1) |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1315 && (tv->v_type != VAR_STRING || !in_vim9script())) |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1316 // number, possibly hidden |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1317 n = (long)tv_get_number(tv); |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1318 |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1319 // Avoid setting a string option to the text "v:false" or similar. |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1320 // In Vim9 script also don't convert a number to string. |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1321 if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1322 && (!in_vim9script() || tv->v_type != VAR_NUMBER)) |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1323 s = tv_get_string_chk(tv); |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1324 |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1325 if (op != NULL && *op != '=') |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 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
|
1328 || (opt_type == 0 && *op != '.')) |
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 semsg(_(e_letwrong), op); |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1331 failed = TRUE; // don't set the value |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1332 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 else |
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 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
|
1337 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 switch (*op) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 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
|
1341 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
|
1342 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
|
1343 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
|
1344 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
|
1345 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 } |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1347 else if (opt_type == 0 && stringval != NULL && s != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 { |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1349 // string |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 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
|
1351 vim_free(stringval); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 stringval = s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 } |
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 } |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1356 |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1357 if (!failed) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 { |
21839
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1359 if (opt_type != 0 || s != NULL) |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1360 { |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1361 set_option_value(arg, n, s, opt_flags); |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1362 arg_end = p; |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1363 } |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1364 else |
c7699985db00
patch 8.2.1469: Vim9: cannot assign string to string option
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1365 emsg(_(e_stringreq)); |
17873
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 *p = c1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 vim_free(stringval); |
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 // ":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
|
1373 else if (*arg == '@') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1375 if (flags & LET_IS_CONST) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 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
|
1378 return NULL; |
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 ++arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 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
|
1382 semsg(_(e_letwrong), op); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 else if (endchars != NULL |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 && 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
|
1385 emsg(_(e_letunexp)); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 else |
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 char_u *ptofree = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 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
|
1392 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
|
1393 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 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
|
1395 if (s != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 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
|
1398 vim_free(s); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 } |
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 if (p != NULL) |
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 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
|
1404 arg_end = arg + 1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 vim_free(ptofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 } |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 // ":let var = expr": Set internal variable. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1411 // ":let var: type = expr": Set internal variable with type. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 // ":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
|
1413 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
|
1414 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 lval_T lv; |
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 p = get_lval(arg, tv, &lv, FALSE, FALSE, 0, FNE_CHECK_START); |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
1418 if (p != NULL && lv.ll_name != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1420 if (endchars != NULL && vim_strchr(endchars, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1421 *skipwhite(lv.ll_name_end)) == NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 emsg(_(e_letunexp)); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1425 set_var_lval(&lv, p, tv, copy, flags, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 arg_end = p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 clear_lval(&lv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 semsg(_(e_invarg2), arg); |
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 return arg_end; |
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 |
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 * ":unlet[!] var1 ... " command. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 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
|
1443 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1444 ex_unletlock(eap, eap->arg, 0, 0, do_unlet_var, NULL); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 |
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 * ":lockvar" and ":unlockvar" commands |
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 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 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
|
1452 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 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
|
1454 int deep = 2; |
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 if (eap->forceit) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 deep = -1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 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
|
1459 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 deep = getdigits(&arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1464 ex_unletlock(eap, arg, deep, 0, do_lock_var, NULL); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 |
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 * ":unlet", ":lockvar" and ":unlockvar" are quite similar. |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1469 * Also used for Vim9 script. "callback" is invoked as: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1470 * callback(&lv, name_end, eap, deep, cookie) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 */ |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1472 void |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 ex_unletlock( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 exarg_T *eap, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 char_u *argstart, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1476 int deep, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1477 int glv_flags, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1478 int (*callback)(lval_T *, char_u *, exarg_T *, int, void *), |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1479 void *cookie) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 char_u *arg = argstart; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 char_u *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 int error = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 lval_T lv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 do |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 if (*arg == '$') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1490 lv.ll_name = arg; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1491 lv.ll_tv = NULL; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1492 ++arg; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 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
|
1494 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1495 semsg(_(e_invarg2), arg - 1); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1498 if (!error && !eap->skip |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1499 && callback(&lv, arg, eap, deep, cookie) == FAIL) |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1500 error = TRUE; |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1501 name_end = arg; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 } |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1503 else |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1504 { |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1505 // Parse the name and find the end. |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1506 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1507 glv_flags, FNE_CHECK_START); |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1508 if (lv.ll_name == NULL) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1509 error = TRUE; // error but continue parsing |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1510 if (name_end == NULL || (!VIM_ISWHITE(*name_end) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1511 && !ends_excmd(*name_end))) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 { |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1513 if (name_end != NULL) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1514 { |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1515 emsg_severe = TRUE; |
21461
4dfd00f481fb
patch 8.2.1281: the "trailing characters" error can be hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
21447
diff
changeset
|
1516 semsg(_(e_trailing_arg), name_end); |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1517 } |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1518 if (!(eap->skip || error)) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1519 clear_lval(&lv); |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1520 break; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 } |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1522 |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1523 if (!error && !eap->skip |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1524 && callback(&lv, name_end, eap, deep, cookie) == FAIL) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1525 error = TRUE; |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1526 |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1527 if (!eap->skip) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 clear_lval(&lv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 arg = skipwhite(name_end); |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1532 } while (!ends_excmd2(name_end, arg)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 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
|
1535 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 static int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 do_unlet_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 lval_T *lp, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 char_u *name_end, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1541 exarg_T *eap, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1542 int deep UNUSED, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1543 void *cookie UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1545 int forceit = eap->forceit; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 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
|
1550 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 cc = *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 *name_end = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1554 // Environment variable, normal name or expanded name. |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1555 if (*lp->ll_name == '$') |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1556 vim_unsetenv(lp->ll_name + 1); |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1557 else if (do_unlet(lp->ll_name, forceit) == FAIL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 ret = FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 *name_end = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1560 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 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
|
1562 && 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
|
1563 || (lp->ll_dict != NULL |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 && 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
|
1565 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 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
|
1567 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 listitem_T *li; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 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
|
1570 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
|
1571 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 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
|
1573 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 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
|
1575 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
|
1576 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 ll_li = li; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 ++ll_n1; |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 // 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
|
1582 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
|
1583 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 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
|
1585 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
|
1586 lp->ll_li = li; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 ++lp->ll_n1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 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
|
1593 // unlet a List item. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 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
|
1595 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 // unlet a Dictionary item. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 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
|
1598 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 * "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
|
1605 * 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
|
1606 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 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
|
1609 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 hashtab_T *ht; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 char_u *varname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 dict_T *d; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
1616 if (in_vim9script() && check_vim9_unlet(name) == FAIL) |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1617 return FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1618 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 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
|
1620 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
|
1621 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 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
|
1623 if (d == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 if (ht == &globvarht) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 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
|
1627 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
|
1628 d = &vimvardict; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 else |
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 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
|
1632 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
|
1633 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 if (d == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 internal_error("do_unlet()"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 } |
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 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
|
1641 if (HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 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
|
1643 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
|
1644 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 di = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 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
|
1647 || 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
|
1648 || 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
|
1649 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 delete_var(ht, hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 } |
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 (forceit) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 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
|
1658 return FAIL; |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 * 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
|
1663 * "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
|
1664 * "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
|
1665 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 static int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 do_lock_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 lval_T *lp, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 char_u *name_end, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1670 exarg_T *eap, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 int deep, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1672 void *cookie UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1674 int lock = eap->cmdidx == CMD_lockvar; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1677 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 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
|
1680 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 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
|
1683 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 cc = *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 *name_end = NUL; |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1686 if (*lp->ll_name == '$') |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1687 { |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1688 semsg(_(e_lock_unlock), lp->ll_name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 ret = FAIL; |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1690 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1693 // Normal name or expanded name. |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1694 di = find_var(lp->ll_name, NULL, TRUE); |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1695 if (di == NULL) |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1696 ret = FAIL; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1697 else if ((di->di_flags & DI_FLAGS_FIX) |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1698 && di->di_tv.v_type != VAR_DICT |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1699 && di->di_tv.v_type != VAR_LIST) |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1700 { |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1701 // For historic reasons this error is not given for a list or |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1702 // dict. E.g., the b: dict could be locked/unlocked. |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1703 semsg(_(e_lock_unlock), lp->ll_name); |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1704 ret = FAIL; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1705 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 else |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1707 { |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1708 if (lock) |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1709 di->di_flags |= DI_FLAGS_LOCK; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1710 else |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1711 di->di_flags &= ~DI_FLAGS_LOCK; |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1712 item_lock(&di->di_tv, deep, lock, FALSE); |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1713 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 *name_end = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 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
|
1718 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 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
|
1720 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1721 // (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
|
1722 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
|
1723 { |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1724 item_lock(&li->li_tv, deep, lock, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 li = li->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 ++lp->ll_n1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 } |
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 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
|
1730 // (un)lock a List item. |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1731 item_lock(&lp->ll_li->li_tv, deep, lock, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1732 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 // (un)lock a Dictionary item. |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1734 item_lock(&lp->ll_di->di_tv, deep, lock, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 * Lock or unlock an item. "deep" is nr of levels to go. |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1741 * When "check_refcount" is TRUE do not lock a list or dict with a reference |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1742 * count larger than 1. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 static void |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1745 item_lock(typval_T *tv, int deep, int lock, int check_refcount) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 static int recurse = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 listitem_T *li; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 dict_T *d; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 blob_T *b; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 if (recurse >= DICT_MAXNEST) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1757 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
|
1758 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 if (deep == 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 ++recurse; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 // 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
|
1765 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 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
|
1767 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 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
|
1769 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 switch (tv->v_type) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 case VAR_UNKNOWN: |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19916
diff
changeset
|
1773 case VAR_ANY: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1774 case VAR_VOID: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 case VAR_NUMBER: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1776 case VAR_BOOL: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 case VAR_STRING: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 case VAR_FUNC: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 case VAR_PARTIAL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 case VAR_FLOAT: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 case VAR_SPECIAL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 case VAR_JOB: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 case VAR_CHANNEL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 case VAR_BLOB: |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1787 if ((b = tv->vval.v_blob) != NULL |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1788 && !(check_refcount && b->bv_refcount > 1)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 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
|
1792 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 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
|
1794 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1795 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 case VAR_LIST: |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1797 if ((l = tv->vval.v_list) != NULL |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1798 && !(check_refcount && l->lv_refcount > 1)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 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
|
1802 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 l->lv_lock &= ~VAR_LOCKED; |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
1804 if ((deep < 0 || deep > 1) && l->lv_first != &range_list_item) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 // recursive: lock/unlock the items the List contains |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19860
diff
changeset
|
1806 FOR_ALL_LIST_ITEMS(l, li) |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1807 item_lock(&li->li_tv, deep - 1, lock, check_refcount); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 case VAR_DICT: |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1811 if ((d = tv->vval.v_dict) != NULL |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1812 && !(check_refcount && d->dv_refcount > 1)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 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
|
1816 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 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
|
1818 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
|
1819 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 // 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
|
1821 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
|
1822 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
|
1823 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 --todo; |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1827 item_lock(&HI2DI(hi)->di_tv, deep - 1, lock, |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
1828 check_refcount); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 --recurse; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1837 #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
|
1838 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1839 * 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
|
1840 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1841 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1842 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
|
1843 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1844 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
|
1845 int todo; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1846 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1847 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
|
1848 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
|
1849 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
|
1850 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1851 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
|
1852 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1853 --todo; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1854 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
|
1855 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
|
1856 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1857 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1858 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
|
1859 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1860 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1861 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1863 * 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
|
1864 * 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
|
1865 * 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
|
1866 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1867 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1868 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
|
1869 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
|
1870 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1871 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1872 * 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
|
1873 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1874 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
|
1875 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
|
1876 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1877 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
|
1878 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1879 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
|
1880 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
|
1881 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1882 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
|
1883 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
|
1884 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
|
1885 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
|
1886 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1887 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
|
1888 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
|
1889 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1890 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
|
1891 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1892 *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
|
1893 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
|
1894 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
|
1895 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
|
1896 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1897 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1898 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1899 * 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
|
1900 * (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
|
1901 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1902 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
|
1903 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
|
1904 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1905 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
|
1906 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
|
1907 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
|
1908 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
|
1909 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
|
1910 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
|
1911 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
|
1912 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1913 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
|
1914 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1915 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
|
1916 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
|
1917 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1918 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1919 // 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
|
1920 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
|
1921 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1922 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
|
1923 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
|
1924 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1925 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1926 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
|
1927 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1928 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
|
1929 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
|
1930 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
|
1931 } |
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 // 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
|
1934 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
|
1935 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
|
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 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
|
1938 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
|
1939 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1940 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1941 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
|
1942 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1943 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
|
1944 } |
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 // 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
|
1947 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
|
1948 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
|
1949 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1950 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
|
1951 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
|
1952 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1953 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1954 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
|
1955 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1956 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
|
1957 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1958 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1959 // 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
|
1960 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
|
1961 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
|
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 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
|
1964 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
|
1965 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1966 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1967 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
|
1968 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1969 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
|
1970 } |
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 // 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
|
1973 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
|
1974 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
|
1975 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
1976 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
|
1977 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
|
1978 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
|
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 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1981 char * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1982 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
|
1983 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1984 switch (nr) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1985 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1986 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
|
1987 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
|
1988 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
|
1989 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
|
1990 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1991 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
|
1992 return "42"; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1993 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1994 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1995 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1996 * 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
|
1997 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1998 dict_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
1999 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
|
2000 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2001 return &globvardict; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2002 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2003 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2004 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2005 * 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
|
2006 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2007 hashtab_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2008 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
|
2009 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2010 return &globvarht; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2011 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2012 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2013 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2014 * 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
|
2015 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2016 dict_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2017 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
|
2018 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2019 return &vimvardict; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2020 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2021 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2022 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2023 * Returns the index of a v:variable. Negative if not found. |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2024 * Returns DI_ flags in "di_flags". |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2025 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2026 int |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2027 find_vim_var(char_u *name, int *di_flags) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2028 { |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2029 dictitem_T *di = find_var_in_ht(&vimvarht, 0, name, TRUE); |
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2030 struct vimvar *vv; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2031 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2032 if (di == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2033 return -1; |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2034 *di_flags = di->di_flags; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2035 vv = (struct vimvar *)((char *)di - offsetof(vimvar_T, vv_di)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2036 return (int)(vv - vimvars); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2037 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2038 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2039 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2040 /* |
17887
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2041 * Set type of v: variable to "type". |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2042 */ |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2043 void |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2044 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
|
2045 { |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2046 vimvars[idx].vv_type = type; |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2047 } |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2048 |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2049 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2050 * 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
|
2051 * 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
|
2052 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2053 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2054 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
|
2055 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2056 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
|
2057 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2058 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2059 char * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2060 get_vim_var_name(int idx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2061 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2062 return vimvars[idx].vv_name; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2063 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2064 |
17885
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 * 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
|
2067 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2068 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
|
2069 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
|
2070 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2071 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
|
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 /* |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2075 * Set v: variable to "tv". Only accepts the same type. |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2076 * Takes over the value of "tv". |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2077 */ |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2078 int |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2079 set_vim_var_tv(int idx, typval_T *tv) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2080 { |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2081 if (vimvars[idx].vv_type != tv->v_type) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2082 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21819
diff
changeset
|
2083 emsg(_(e_type_mismatch_for_v_variable)); |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2084 clear_tv(tv); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2085 return FAIL; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2086 } |
19962
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2087 // VV_RO is also checked when compiling, but let's check here as well. |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2088 if (vimvars[idx].vv_flags & VV_RO) |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2089 { |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2090 semsg(_(e_readonlyvar), vimvars[idx].vv_name); |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2091 return FAIL; |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2092 } |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2093 if (sandbox && (vimvars[idx].vv_flags & VV_RO_SBX)) |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2094 { |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2095 semsg(_(e_readonlysbx), vimvars[idx].vv_name); |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2096 return FAIL; |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2097 } |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2098 clear_tv(&vimvars[idx].vv_di.di_tv); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2099 vimvars[idx].vv_di.di_tv = *tv; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2100 return OK; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2101 } |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2102 |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2103 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2104 * 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
|
2105 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2106 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
|
2107 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
|
2108 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2109 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
|
2110 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2111 |
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 * 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
|
2114 * 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
|
2115 * 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
|
2116 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2117 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
|
2118 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
|
2119 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2120 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
|
2121 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2122 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2123 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2124 * 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
|
2125 * needed. |
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 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
|
2128 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
|
2129 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2130 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
|
2131 } |
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 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2134 * 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
|
2135 * needed. |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2136 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2137 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
|
2138 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
|
2139 { |
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 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
|
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 * 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
|
2145 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2146 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2147 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
|
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 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
|
2150 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2151 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
|
2152 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
|
2153 else |
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 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
|
2156 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
|
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 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2161 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2162 * 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
|
2163 * 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
|
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 void |
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_vcount( |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2167 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
|
2168 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
|
2169 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
|
2170 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2171 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
|
2172 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
|
2173 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
|
2174 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
|
2175 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2176 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2177 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2178 * 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
|
2179 * 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
|
2180 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2181 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2182 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
|
2183 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2184 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
|
2185 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
|
2186 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
|
2187 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2188 |
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 * 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
|
2191 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2192 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2193 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
|
2194 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2195 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
|
2196 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
|
2197 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
|
2198 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2199 |
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 * 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
|
2202 * value. |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2203 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2204 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2205 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
|
2206 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
|
2207 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
|
2208 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
|
2209 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2210 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
|
2211 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
|
2212 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
|
2213 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
|
2214 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
|
2215 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
|
2216 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2217 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
|
2218 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2219 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2220 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2221 * 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
|
2222 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2223 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2224 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
|
2225 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2226 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
|
2227 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
|
2228 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
|
2229 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
|
2230 ++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
|
2231 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2232 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2233 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2234 * 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
|
2235 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2236 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2237 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
|
2238 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2239 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
|
2240 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
|
2241 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
|
2242 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
|
2243 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2244 ++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
|
2245 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
|
2246 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2247 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2248 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2249 /* |
18477
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2250 * 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
|
2251 */ |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2252 void |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2253 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
|
2254 { |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2255 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
|
2256 int i; |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2257 |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2258 if (l == NULL) |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2259 getout(1); |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2260 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
|
2261 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
|
2262 { |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2263 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
|
2264 getout(1); |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19201
diff
changeset
|
2265 l->lv_u.mat.lv_last->li_tv.v_lock = VAR_FIXED; |
18477
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2266 } |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2267 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
|
2268 } |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2269 |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2270 /* |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2271 * Reset v:register, taking the 'clipboard' setting into account. |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2272 */ |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2273 void |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2274 reset_reg_var(void) |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2275 { |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2276 int regname = 0; |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2277 |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2278 // Adjust the register according to 'clipboard', so that when |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2279 // "unnamed" is present it becomes '*' or '+' instead of '"'. |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2280 #ifdef FEAT_CLIPBOARD |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2281 adjust_clip_reg(®name); |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2282 #endif |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2283 set_reg_var(regname); |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2284 } |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2285 |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2286 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2287 * 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
|
2288 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2289 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2290 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
|
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 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
|
2293 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2294 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
|
2295 regname = '"'; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2296 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2297 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
|
2298 // 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
|
2299 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
|
2300 set_vim_var_string(VV_REG, ®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
|
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 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2304 * 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
|
2305 * 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
|
2306 * 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
|
2307 * 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
|
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 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
|
2310 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
|
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 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
|
2313 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
|
2314 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2315 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
|
2316 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
|
2317 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2318 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2319 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2320 * 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
|
2321 * 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
|
2322 * 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
|
2323 * 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
|
2324 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2325 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
|
2326 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
|
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 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
|
2329 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
|
2330 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2331 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
|
2332 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
|
2333 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2334 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2335 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2336 * 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
|
2337 * 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
|
2338 * 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
|
2339 * 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
|
2340 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2341 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
|
2342 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
|
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 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
|
2345 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
|
2346 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
|
2347 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2348 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
|
2349 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
|
2350 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2351 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
|
2352 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
|
2353 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
|
2354 } |
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 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
|
2357 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
|
2358 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
|
2359 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
|
2360 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2361 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
|
2362 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2363 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
|
2364 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
|
2365 |
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 (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
|
2367 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
|
2368 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
|
2369 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
|
2370 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
|
2371 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
|
2372 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2373 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
|
2374 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
|
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 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
|
2378 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
|
2379 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
|
2380 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
|
2381 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2382 *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
|
2383 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2384 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
|
2385 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
|
2386 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2387 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
|
2388 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
|
2389 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
|
2390 : 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
|
2391 : "mac"); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2392 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
|
2393 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
|
2394 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
|
2395 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
|
2396 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
|
2397 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
|
2398 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
|
2399 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
|
2400 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
|
2401 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
|
2402 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2405 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 * 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
|
2407 * 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
|
2408 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 int |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
2410 eval_variable( |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2412 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
|
2413 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
|
2414 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
|
2415 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
|
2416 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
|
2417 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2418 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2419 typval_T *tv = NULL; |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2420 int foundFunc = FALSE; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2421 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2422 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2424 // 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
|
2425 cc = name[len]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2426 name[len] = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2428 // 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
|
2429 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
|
2430 if (v != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2432 tv = &v->di_tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2433 if (dip != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2434 *dip = v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2436 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2437 if (tv == NULL && (in_vim9script() || STRNCMP(name, "s:", 2) == 0)) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2438 { |
20816
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
2439 imported_T *import; |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
2440 char_u *p = STRNCMP(name, "s:", 2) == 0 ? name + 2 : name; |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
2441 |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
2442 import = find_imported(p, 0, NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2443 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2444 // imported variable from another script |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2445 if (import != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2446 { |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2447 if (import->imp_funcname != NULL) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2448 { |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2449 foundFunc = TRUE; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2450 if (rettv != NULL) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2451 { |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2452 rettv->v_type = VAR_FUNC; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2453 rettv->vval.v_string = vim_strsave(import->imp_funcname); |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2454 } |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2455 } |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2456 else |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2457 { |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2458 scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
2459 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2460 + import->imp_var_vals_idx; |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2461 tv = sv->sv_tv; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2462 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2463 } |
21955
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2464 else if (in_vim9script()) |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2465 { |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2466 ufunc_T *ufunc = find_func(name, FALSE, NULL); |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2467 |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2468 if (ufunc != NULL) |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2469 { |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2470 foundFunc = TRUE; |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2471 if (rettv != NULL) |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2472 { |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2473 rettv->v_type = VAR_FUNC; |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2474 rettv->vval.v_string = vim_strsave(ufunc->uf_name); |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2475 } |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2476 } |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
2477 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2478 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2479 |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2480 if (!foundFunc) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2481 { |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2482 if (tv == NULL) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2483 { |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2484 if (rettv != NULL && verbose) |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21819
diff
changeset
|
2485 semsg(_(e_undefined_variable_str), name); |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2486 ret = FAIL; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2487 } |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2488 else if (rettv != NULL) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2489 copy_tv(tv, rettv); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2491 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2492 name[len] = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2493 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2494 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2495 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2496 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2498 * 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
|
2499 * 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
|
2500 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2501 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2502 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
|
2503 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2504 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
|
2505 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
|
2506 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
|
2507 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2508 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
|
2509 return; |
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 // 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
|
2512 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
|
2513 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
|
2514 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2515 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
|
2516 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
|
2517 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2518 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
|
2519 *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
|
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 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
|
2523 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2524 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2525 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2526 * 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
|
2527 * 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
|
2528 * 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
|
2529 * 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
|
2530 * 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
|
2531 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2532 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
|
2533 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
|
2534 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2535 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
|
2536 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
|
2537 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
|
2538 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2539 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
|
2540 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
|
2541 *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
|
2542 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
|
2543 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
|
2544 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
|
2545 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
|
2546 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
|
2547 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
2548 // 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
|
2549 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
|
2550 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2551 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2552 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2553 * Find variable "varname" in hashtab "ht" with name "htname". |
19902
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2554 * When "varname" is empty returns curwin/curtab/etc vars dictionary. |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2555 * 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
|
2556 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2557 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
|
2558 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
|
2559 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
|
2560 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
|
2561 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
|
2562 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
|
2563 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2564 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
|
2565 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2566 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
|
2567 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2568 // 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
|
2569 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
|
2570 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2571 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
|
2572 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
|
2573 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
|
2574 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
|
2575 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
|
2576 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
|
2577 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
|
2578 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
|
2579 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2580 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
|
2581 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2582 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2583 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
|
2584 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
|
2585 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2586 // 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
|
2587 // 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
|
2588 // 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
|
2589 // 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
|
2590 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
|
2591 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2592 // 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
|
2593 // 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
|
2594 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
|
2595 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
|
2596 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
|
2597 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2598 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
|
2599 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
|
2600 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2601 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
|
2602 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2603 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2604 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2605 * Get the script-local hashtab. NULL if not in a script context. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2606 */ |
19916
dcec86d796bc
patch 8.2.0514: several global functions are used in only one file
Bram Moolenaar <Bram@vim.org>
parents:
19902
diff
changeset
|
2607 static hashtab_T * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2608 get_script_local_ht(void) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2609 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2610 scid_T sid = current_sctx.sc_sid; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2611 |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21955
diff
changeset
|
2612 if (SCRIPT_ID_VALID(sid)) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2613 return &SCRIPT_VARS(sid); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2614 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2615 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2616 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2617 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2618 * Look for "name[len]" in script-local variables. |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2619 * Return a non-NULL pointer when found, NULL when not found. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2620 */ |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2621 void * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2622 lookup_scriptvar(char_u *name, size_t len, cctx_T *dummy UNUSED) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2623 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2624 hashtab_T *ht = get_script_local_ht(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2625 char_u buffer[30]; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2626 char_u *p; |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2627 void *res; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2628 hashitem_T *hi; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2629 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2630 if (ht == NULL) |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2631 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2632 if (len < sizeof(buffer) - 1) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2633 { |
20326
74002d42dda0
patch 8.2.0718: gcc warning for returning pointer to local variable
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2634 // avoid an alloc/free for short names |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2635 vim_strncpy(buffer, name, len); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2636 p = buffer; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2637 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2638 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2639 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
2640 p = vim_strnsave(name, len); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2641 if (p == NULL) |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2642 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2643 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2644 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2645 hi = hash_find(ht, p); |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2646 res = HASHITEM_EMPTY(hi) ? NULL : hi; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2647 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2648 // if not script-local, then perhaps imported |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2649 if (res == NULL && find_imported(p, 0, NULL) != NULL) |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20233
diff
changeset
|
2650 res = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2651 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2652 if (p != buffer) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2653 vim_free(p); |
20326
74002d42dda0
patch 8.2.0718: gcc warning for returning pointer to local variable
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2654 // Don't return "buffer", gcc complains. |
74002d42dda0
patch 8.2.0718: gcc warning for returning pointer to local variable
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2655 return res == NULL ? NULL : IObuff; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2656 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2657 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2658 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2659 * 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
|
2660 * 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
|
2661 * 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
|
2662 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2663 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
|
2664 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
|
2665 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2666 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
|
2667 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
|
2668 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2669 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
|
2670 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
|
2671 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
|
2672 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2673 // 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
|
2674 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
|
2675 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
|
2676 *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
|
2677 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2678 // "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
|
2679 // 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
|
2680 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
|
2681 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2682 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
|
2683 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
|
2684 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
|
2685 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2686 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2687 ht = get_funccal_local_ht(); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2688 if (ht != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2689 return ht; // local variable |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2690 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2691 // in Vim9 script items at the script level are script-local |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2692 if (in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2693 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2694 ht = get_script_local_ht(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2695 if (ht != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2696 return ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2697 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2698 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2699 return &globvarht; // global 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
|
2700 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2701 *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
|
2702 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
|
2703 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
|
2704 // 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
|
2705 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
|
2706 || 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
|
2707 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
|
2708 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
|
2709 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
|
2710 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
|
2711 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
|
2712 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
|
2713 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
|
2714 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
|
2715 return &vimvarht; |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19524
diff
changeset
|
2716 if (get_current_funccal() != NULL |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20919
diff
changeset
|
2717 && get_current_funccal()->func->uf_def_status == UF_NOT_COMPILED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2718 { |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19524
diff
changeset
|
2719 // a: and l: are only used in functions defined with ":function" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2720 if (*name == 'a') // a: function argument |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2721 return get_funccal_args_ht(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2722 if (*name == 'l') // l: local function variable |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2723 return get_funccal_local_ht(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2724 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2725 if (*name == 's') // script variable |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2726 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2727 ht = get_script_local_ht(); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2728 if (ht != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2729 return ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2730 } |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2731 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
|
2732 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2733 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2734 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2735 * 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
|
2736 * 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
|
2737 * 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
|
2738 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2739 char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2740 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
|
2741 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2742 dictitem_T *v; |
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 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
|
2745 if (v == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2746 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2747 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
|
2748 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2749 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2750 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2751 * 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
|
2752 * 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
|
2753 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2754 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2755 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
|
2756 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2757 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
|
2758 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
2759 sv = ALLOC_CLEAR_ONE(scriptvar_T); |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
2760 if (sv == NULL) |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
2761 return; |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
2762 init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE); |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
2763 SCRIPT_ITEM(id)->sn_vars = sv; |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2764 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2765 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2766 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2767 * 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
|
2768 * 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
|
2769 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2770 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2771 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
|
2772 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2773 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
|
2774 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
|
2775 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
|
2776 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
|
2777 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
|
2778 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
|
2779 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
|
2780 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
|
2781 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
|
2782 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
|
2783 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2784 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2785 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2786 * 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
|
2787 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2788 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2789 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
|
2790 { |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
2791 // 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
|
2792 // 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
|
2793 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
|
2794 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
|
2795 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2796 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2797 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2798 * 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
|
2799 * 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
|
2800 * 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
|
2801 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2802 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2803 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
|
2804 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2805 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
|
2806 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2807 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2808 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2809 * 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
|
2810 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2811 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2812 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
|
2813 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2814 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2815 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2816 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2817 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2818 hash_lock(ht); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2819 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
|
2820 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
|
2821 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2822 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2823 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2824 --todo; |
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 // 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
|
2827 // 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
|
2828 // later. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2829 v = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2830 if (free_val) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2831 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
|
2832 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
|
2833 vim_free(v); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2834 } |
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 hash_clear(ht); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2837 ht->ht_used = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2838 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2841 * 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
|
2842 * 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
|
2843 */ |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2844 static void |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2845 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
|
2846 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2847 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
|
2848 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2849 hash_remove(ht, hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2850 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
|
2851 vim_free(di); |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2854 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2855 * 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
|
2856 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2857 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2858 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
|
2859 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2860 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2861 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2862 char_u numbuf[NUMBUFLEN]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2863 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2864 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
|
2865 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
|
2866 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
|
2867 vim_free(tofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2868 } |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2871 list_one_var_a( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2872 char *prefix, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2873 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2874 int type, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2875 char_u *string, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2876 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
|
2877 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2878 // 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
|
2879 msg_start(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2880 msg_puts(prefix); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2881 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
|
2882 msg_puts((char *)name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2883 msg_putchar(' '); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2884 msg_advance(22); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2885 if (type == VAR_NUMBER) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2886 msg_putchar('#'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2887 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
|
2888 msg_putchar('*'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2889 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
|
2890 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2891 msg_putchar('['); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2892 if (*string == '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2893 ++string; |
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 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
|
2896 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2897 msg_putchar('{'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2898 if (*string == '{') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2899 ++string; |
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 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2902 msg_putchar(' '); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2903 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2904 msg_outtrans(string); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2905 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2906 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
|
2907 msg_puts("()"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2908 if (*first) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2909 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2910 msg_clr_eos(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2911 *first = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2912 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2913 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2914 |
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 * 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
|
2917 * 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
|
2918 * 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
|
2919 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2920 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2921 set_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2922 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2923 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2924 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
|
2925 { |
21150
951aad18b1af
patch 8.2.1126: Vim9: using :copen causes an error
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
2926 set_var_const(name, NULL, tv, copy, LET_NO_COMMAND); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2927 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2930 * 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
|
2931 * 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
|
2932 * 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
|
2933 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2934 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2935 set_var_const( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2936 char_u *name, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2937 type_T *type, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2938 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2939 int copy, // make copy of value in "tv" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2940 int flags) // LET_IS_CONST and/or LET_NO_COMMAND |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2941 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2942 dictitem_T *di; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2943 char_u *varname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2944 hashtab_T *ht; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2945 int is_script_local; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2946 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2947 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
|
2948 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
|
2949 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2950 semsg(_(e_illvar), name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2951 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2952 } |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2953 is_script_local = ht == get_script_local_ht(); |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2954 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2955 if (in_vim9script() |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2956 && !is_script_local |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2957 && (flags & LET_NO_COMMAND) == 0 |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2958 && name[1] == ':') |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2959 { |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2960 vim9_declare_error(name); |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2961 return; |
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2962 } |
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
2963 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2964 di = find_var_in_ht(ht, 0, varname, TRUE); |
17873
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 // Search in parent scope which is possible to reference from lambda |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2967 if (di == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2968 di = find_var_in_scoped_ht(name, TRUE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2969 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2970 if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) |
21691
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
2971 && var_wrong_func_name(name, di == NULL)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2972 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2973 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2974 if (di != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2975 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2976 if ((di->di_flags & DI_FLAGS_RELOAD) == 0) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2977 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2978 if (flags & LET_IS_CONST) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2979 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2980 emsg(_(e_cannot_mod)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2981 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2982 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2983 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2984 if (is_script_local && in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2985 { |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
2986 if ((flags & LET_NO_COMMAND) == 0) |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
2987 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21819
diff
changeset
|
2988 semsg(_(e_redefining_script_item_str), name); |
20842
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
2989 return; |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
2990 } |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
2991 |
bacc2ab11810
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Bram Moolenaar <Bram@vim.org>
parents:
20840
diff
changeset
|
2992 // check the type |
20919
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
2993 if (check_script_var_type(&di->di_tv, tv, name) == FAIL) |
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
2994 return; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2995 } |
20919
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
2996 |
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
2997 if (var_check_ro(di->di_flags, name, FALSE) |
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
2998 || var_check_lock(di->di_tv.v_lock, name, FALSE)) |
96bf2b304932
patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
2999 return; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3000 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3001 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3002 // can only redefine once |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3003 di->di_flags &= ~DI_FLAGS_RELOAD; |
17873
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 // existing variable, need to clear the value |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3006 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3007 // Handle setting internal di: variables separately where needed to |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3008 // 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
|
3009 if (ht == &vimvarht) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3010 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3011 if (di->di_tv.v_type == VAR_STRING) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3012 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3013 VIM_CLEAR(di->di_tv.vval.v_string); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3014 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
|
3015 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3016 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
|
3017 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3018 // Careful: when assigning to v:errmsg and tv_get_string() |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
19191
diff
changeset
|
3019 // causes an error message the variable will already be set. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3020 if (di->di_tv.vval.v_string == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3021 di->di_tv.vval.v_string = vim_strsave(val); |
17873
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 // Take over the string to avoid an extra alloc/free. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3026 di->di_tv.vval.v_string = tv->vval.v_string; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3027 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
|
3028 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3029 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3030 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3031 else if (di->di_tv.v_type == VAR_NUMBER) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3032 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3033 di->di_tv.vval.v_number = tv_get_number(tv); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3034 if (STRCMP(varname, "searchforward") == 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3035 set_search_direction(di->di_tv.vval.v_number ? '/' : '?'); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3036 #ifdef FEAT_SEARCH_EXTRA |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3037 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
|
3038 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3039 no_hlsearch = !di->di_tv.vval.v_number; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3040 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
|
3041 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3042 #endif |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3043 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3044 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3045 else if (di->di_tv.v_type != tv->v_type) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3046 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3047 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
|
3048 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3049 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3050 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3051 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3052 clear_tv(&di->di_tv); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3053 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3054 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
|
3055 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3056 // 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
|
3057 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
|
3058 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3059 semsg(_(e_illvar), name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3060 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3061 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3062 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3063 // 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
|
3064 if (!valid_varname(varname)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3065 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3066 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3067 di = alloc(sizeof(dictitem_T) + STRLEN(varname)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3068 if (di == NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3069 return; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3070 STRCPY(di->di_key, varname); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3071 if (hash_add(ht, DI2HIKEY(di)) == FAIL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3072 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3073 vim_free(di); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3074 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3075 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3076 di->di_flags = DI_FLAGS_ALLOC; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3077 if (flags & LET_IS_CONST) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3078 di->di_flags |= DI_FLAGS_LOCK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3079 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
3080 if (is_script_local && in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3081 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
3082 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3083 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3084 // Store a pointer to the typval_T, so that it can be found by |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3085 // index instead of using a hastab lookup. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3086 if (ga_grow(&si->sn_var_vals, 1) == OK) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3087 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3088 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3089 + si->sn_var_vals.ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3090 sv->sv_name = di->di_key; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3091 sv->sv_tv = &di->di_tv; |
21819
e3b429b995a6
patch 8.2.1459: Vim9: declaring script var in script does not infer the type
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
3092 if (type == NULL) |
e3b429b995a6
patch 8.2.1459: Vim9: declaring script var in script does not infer the type
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
3093 sv->sv_type = typval2type(tv, &si->sn_type_list); |
e3b429b995a6
patch 8.2.1459: Vim9: declaring script var in script does not infer the type
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
3094 else |
e3b429b995a6
patch 8.2.1459: Vim9: declaring script var in script does not infer the type
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
3095 sv->sv_type = type; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3096 sv->sv_const = (flags & LET_IS_CONST); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3097 sv->sv_export = is_export; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3098 ++si->sn_var_vals.ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3099 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3100 // let ex_export() know the export worked. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3101 is_export = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3102 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3103 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3104 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3105 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3106 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3107 copy_tv(tv, &di->di_tv); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3108 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3109 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3110 di->di_tv = *tv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3111 di->di_tv.v_lock = 0; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3112 init_tv(tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3113 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3114 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3115 if (flags & LET_IS_CONST) |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
3116 // Like :lockvar! name: lock the value and what it contains, but only |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
3117 // if the reference count is up to one. That locks only literal |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
3118 // values. |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
3119 item_lock(&di->di_tv, DICT_MAXNEST, TRUE, TRUE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3120 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3121 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3122 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3123 * 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
|
3124 * 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
|
3125 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3126 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3127 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
|
3128 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3129 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
|
3130 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3131 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
|
3132 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3133 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3134 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
|
3135 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3136 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
|
3137 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3138 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3139 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3140 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3141 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3142 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3143 * 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
|
3144 * 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
|
3145 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3146 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3147 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
|
3148 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3149 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
|
3150 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3151 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
|
3152 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
|
3153 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3154 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3155 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3156 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3157 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3158 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3159 * 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
|
3160 * 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
|
3161 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3162 int |
21691
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
3163 var_wrong_func_name( |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3164 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
|
3165 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
|
3166 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3167 // 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
|
3168 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
|
3169 && !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
|
3170 ? name[2] : name[0])) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3171 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3172 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
|
3173 name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3174 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3175 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3176 // 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
|
3177 // 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
|
3178 // below. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3179 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
|
3180 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3181 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
|
3182 name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3183 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3184 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3185 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3186 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3187 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3188 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3189 * 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
|
3190 * 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
|
3191 * TRUE. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3192 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3193 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3194 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
|
3195 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3196 if (lock & VAR_LOCKED) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3197 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3198 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
|
3199 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
|
3200 : 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
|
3201 : name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3202 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3203 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3204 if (lock & VAR_FIXED) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3205 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3206 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
|
3207 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
|
3208 : 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
|
3209 : name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3210 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3211 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3212 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3213 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3214 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3215 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3216 * 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
|
3217 * 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
|
3218 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3219 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3220 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
|
3221 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3222 char_u *p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3223 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3224 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
|
3225 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
|
3226 && *p != AUTOLOAD_CHAR) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3227 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3228 semsg(_(e_illvar), varname); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3229 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3230 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3231 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3232 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3233 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3234 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3235 * getwinvar() and gettabwinvar() |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3236 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3237 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3238 getwinvar( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3239 typval_T *argvars, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3240 typval_T *rettv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3241 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
|
3242 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3243 win_T *win; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3244 char_u *varname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3245 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3246 tabpage_T *tp = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3247 int done = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3248 win_T *oldcurwin; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3249 tabpage_T *oldtabpage; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3250 int need_switch_win; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3251 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3252 if (off == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3253 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
|
3254 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3255 tp = curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3256 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
|
3257 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
|
3258 ++emsg_off; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3259 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3260 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
|
3261 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
|
3262 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3263 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
|
3264 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3265 // 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
|
3266 // 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
|
3267 // autocommands get blocked. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3268 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
|
3269 if (!need_switch_win |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3270 || 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
|
3271 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3272 if (*varname == '&') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3273 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3274 if (varname[1] == NUL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3275 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3276 // 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
|
3277 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
|
3278 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3279 if (opts != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3280 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3281 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
|
3282 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3283 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3284 } |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
3285 else if (eval_option(&varname, rettv, 1) == OK) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3286 // window-local-option |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3287 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3288 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3289 else |
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 // Look up the variable. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3292 // 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
|
3293 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
|
3294 varname, FALSE); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3295 if (v != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3296 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3297 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
|
3298 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3299 } |
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 } |
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 if (need_switch_win) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3304 // 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
|
3305 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
|
3306 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3307 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3308 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
|
3309 // 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
|
3310 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
|
3311 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3312 --emsg_off; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3313 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3314 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3315 /* |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3316 * Set option "varname" to the value of "varp" for the current buffer/window. |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3317 */ |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3318 static void |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3319 set_option_from_tv(char_u *varname, typval_T *varp) |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3320 { |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3321 long numval = 0; |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3322 char_u *strval; |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3323 char_u nbuf[NUMBUFLEN]; |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3324 int error = FALSE; |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3325 |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3326 if (!in_vim9script() || varp->v_type != VAR_STRING) |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3327 numval = (long)tv_get_number_chk(varp, &error); |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3328 strval = tv_get_string_buf_chk(varp, nbuf); |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3329 if (!error && strval != NULL) |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3330 set_option_value(varname, numval, strval, OPT_LOCAL); |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3331 } |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3332 |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3333 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3334 * "setwinvar()" and "settabwinvar()" functions |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3335 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3336 static void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
3337 setwinvar(typval_T *argvars, int off) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3338 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3339 win_T *win; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3340 win_T *save_curwin; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3341 tabpage_T *save_curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3342 int need_switch_win; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3343 char_u *varname, *winvarname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3344 typval_T *varp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3345 tabpage_T *tp = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3346 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3347 if (check_secure()) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3348 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3349 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3350 if (off == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3351 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
|
3352 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3353 tp = curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3354 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
|
3355 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
|
3356 varp = &argvars[off + 2]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3357 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3358 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
|
3359 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3360 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
|
3361 if (!need_switch_win |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3362 || 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
|
3363 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3364 if (*varname == '&') |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3365 set_option_from_tv(varname + 1, varp); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3366 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3367 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3368 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
|
3369 if (winvarname != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3370 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3371 STRCPY(winvarname, "w:"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3372 STRCPY(winvarname + 2, varname); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3373 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
|
3374 vim_free(winvarname); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3375 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3376 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3377 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3378 if (need_switch_win) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3379 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
|
3380 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3381 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3382 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3383 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3384 * 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
|
3385 * 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
|
3386 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3387 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3388 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
|
3389 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3390 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
|
3391 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
|
3392 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
|
3393 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
|
3394 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
|
3395 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
|
3396 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3397 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3398 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3399 * 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
|
3400 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3401 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3402 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
|
3403 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3404 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
|
3405 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3406 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
|
3407 // 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
|
3408 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
|
3409 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
|
3410 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3411 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3412 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3413 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
|
3414 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
3415 char_u *arg = var; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3416 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3417 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3418 typval_T tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3419 int len = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3420 int n = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3421 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3422 // 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
|
3423 name = var; |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
3424 len = get_name_len(&arg, &tofree, TRUE, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3425 if (len > 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3426 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3427 if (tofree != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3428 name = tofree; |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
3429 n = (eval_variable(name, len, &tv, NULL, FALSE, TRUE) == OK); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3430 if (n) |
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 // handle d.key, l[idx], f(expr) |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
3433 arg = skipwhite(arg); |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
3434 n = (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, FALSE) == OK); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3435 if (n) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3436 clear_tv(&tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3437 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3438 } |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
3439 if (*arg != NUL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3440 n = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3441 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3442 vim_free(tofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3443 return n; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3444 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3445 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3446 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
|
3447 #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
|
3448 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
|
3449 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
|
3450 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
|
3451 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3452 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3453 * 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
|
3454 * 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
|
3455 * 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
|
3456 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3457 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3458 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
|
3459 { |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
3460 int called_emsg_before; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3461 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
|
3462 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3463 // 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
|
3464 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
|
3465 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3466 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
|
3467 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3468 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3469 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3470 // 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
|
3471 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
|
3472 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
|
3473 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3474 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3475 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
|
3476 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
|
3477 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3478 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
|
3479 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3480 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3481 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3482 // 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
|
3483 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
|
3484 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3485 // 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
|
3486 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
|
3487 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
|
3488 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
|
3489 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3490 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
|
3491 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
|
3492 // Trailing characters are present after the variable name |
21461
4dfd00f481fb
patch 8.2.1281: the "trailing characters" error can be hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
21447
diff
changeset
|
3493 semsg(_(e_trailing_arg), redir_endp); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3494 else |
21461
4dfd00f481fb
patch 8.2.1281: the "trailing characters" error can be hard to understand
Bram Moolenaar <Bram@vim.org>
parents:
21447
diff
changeset
|
3495 semsg(_(e_invarg2), name); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3496 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
|
3497 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
|
3498 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3499 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3500 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3501 // 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
|
3502 // string |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
3503 called_emsg_before = called_emsg; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3504 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
|
3505 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
|
3506 if (append) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3507 set_var_lval(redir_lval, redir_endp, &tv, TRUE, 0, (char_u *)"."); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3508 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3509 set_var_lval(redir_lval, redir_endp, &tv, TRUE, 0, (char_u *)"="); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3510 clear_lval(redir_lval); |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
3511 if (called_emsg > called_emsg_before) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3512 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3513 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
|
3514 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
|
3515 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3516 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3517 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3518 return OK; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3519 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3520 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3521 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3522 * 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
|
3523 * 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
|
3524 * 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
|
3525 * 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
|
3526 * :redir => foo |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3527 * :let foo |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3528 * :redir END |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3529 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3530 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3531 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
|
3532 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3533 int len; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3534 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3535 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
|
3536 return; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3537 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3538 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
|
3539 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
|
3540 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3541 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
|
3542 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3543 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
|
3544 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3545 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
|
3546 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
|
3547 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3548 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3549 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
|
3550 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3551 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3552 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3553 * 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
|
3554 * 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
|
3555 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3556 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3557 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
|
3558 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3559 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
|
3560 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3561 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
|
3562 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3563 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
|
3564 return; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3565 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3566 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3567 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
|
3568 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3569 // 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
|
3570 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
|
3571 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3572 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
|
3573 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
|
3574 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
|
3575 // 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
|
3576 // have changed. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3577 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
|
3578 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
|
3579 if (redir_endp != NULL && redir_lval->ll_name != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3580 set_var_lval(redir_lval, redir_endp, &tv, FALSE, 0, |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3581 (char_u *)"."); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3582 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
|
3583 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3584 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3585 // 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
|
3586 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
|
3587 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3588 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
|
3589 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3590 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
|
3591 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
3592 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3593 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3594 * "gettabvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3595 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3596 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3597 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
|
3598 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3599 win_T *oldcurwin; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3600 tabpage_T *tp, *oldtabpage; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3601 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3602 char_u *varname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3603 int done = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3604 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3605 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
|
3606 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
|
3607 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3608 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
|
3609 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
|
3610 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
|
3611 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3612 // 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
|
3613 // 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
|
3614 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
|
3615 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
|
3616 : 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
|
3617 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3618 // look up the variable |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3619 // 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
|
3620 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
|
3621 if (v != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3622 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3623 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
|
3624 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3625 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3626 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3627 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3628 // 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
|
3629 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
|
3630 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3631 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3632 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
|
3633 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
|
3634 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3635 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3636 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3637 * "gettabwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3638 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3639 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3640 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
|
3641 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3642 getwinvar(argvars, rettv, 1); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3643 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3644 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3645 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3646 * "getwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3647 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3648 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3649 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
|
3650 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3651 getwinvar(argvars, rettv, 0); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3652 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3653 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3654 /* |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3655 * "getbufvar()" function |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3656 */ |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3657 void |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3658 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
|
3659 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3660 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
|
3661 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
|
3662 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
|
3663 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
|
3664 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3665 varname = tv_get_string_chk(&argvars[1]); |
22027
ee967cdcf749
patch 8.2.1563: Vim9: error when using '%" with setbufvar() r getbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
3666 buf = tv_get_buf_from_arg(&argvars[0]); |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3667 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3668 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
|
3669 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
|
3670 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3671 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
|
3672 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3673 if (*varname == '&') |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3674 { |
19834
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3675 buf_T *save_curbuf = curbuf; |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3676 |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3677 // set curbuf to be our buf, temporarily |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3678 curbuf = buf; |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3679 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3680 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
|
3681 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3682 // 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
|
3683 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
|
3684 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3685 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
|
3686 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3687 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
|
3688 done = TRUE; |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3689 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3690 } |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21056
diff
changeset
|
3691 else if (eval_option(&varname, rettv, TRUE) == OK) |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3692 // 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
|
3693 done = TRUE; |
19834
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3694 |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3695 // restore previous notion of curbuf |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3696 curbuf = save_curbuf; |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3697 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3698 else |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3699 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3700 // Look up the variable. |
19902
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3701 if (*varname == NUL) |
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3702 // Let getbufvar({nr}, "") return the "b:" dictionary. |
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3703 v = &buf->b_bufvar; |
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3704 else |
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3705 v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', |
481e8fa158b4
patch 8.2.0507: getbufvar() may get the wrong dictionary
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3706 varname, FALSE); |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3707 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
|
3708 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3709 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
|
3710 done = TRUE; |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3711 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3712 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3713 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3714 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3715 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
|
3716 // 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
|
3717 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
|
3718 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3719 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3720 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3721 * "settabvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3722 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3723 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
3724 f_settabvar(typval_T *argvars, typval_T *rettv UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3725 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3726 tabpage_T *save_curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3727 tabpage_T *tp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3728 char_u *varname, *tabvarname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3729 typval_T *varp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3730 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3731 if (check_secure()) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3732 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3733 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3734 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
|
3735 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
|
3736 varp = &argvars[2]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3737 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3738 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
|
3739 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3740 save_curtab = curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3741 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
|
3742 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3743 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
|
3744 if (tabvarname != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3745 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3746 STRCPY(tabvarname, "t:"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3747 STRCPY(tabvarname + 2, varname); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3748 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
|
3749 vim_free(tabvarname); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3750 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3751 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3752 // Restore current tabpage |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3753 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
|
3754 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
|
3755 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3756 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3757 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3758 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3759 * "settabwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3760 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3761 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
3762 f_settabwinvar(typval_T *argvars, typval_T *rettv UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3763 { |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
3764 setwinvar(argvars, 1); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3765 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3766 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3767 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3768 * "setwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3769 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3770 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
3771 f_setwinvar(typval_T *argvars, typval_T *rettv UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3772 { |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
3773 setwinvar(argvars, 0); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3774 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3775 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3776 /* |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3777 * "setbufvar()" function |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3778 */ |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3779 void |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3780 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
|
3781 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3782 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
|
3783 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
|
3784 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
|
3785 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3786 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
|
3787 return; |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3788 varname = tv_get_string_chk(&argvars[1]); |
22027
ee967cdcf749
patch 8.2.1563: Vim9: error when using '%" with setbufvar() r getbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
3789 buf = tv_get_buf_from_arg(&argvars[0]); |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3790 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
|
3791 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3792 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
|
3793 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3794 if (*varname == '&') |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3795 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3796 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
|
3797 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3798 // 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
|
3799 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
|
3800 |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
3801 set_option_from_tv(varname + 1, varp); |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3802 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3803 // 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
|
3804 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
|
3805 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3806 else |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3807 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3808 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
|
3809 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
|
3810 { |
19834
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3811 buf_T *save_curbuf = curbuf; |
2ef25a007bb7
patch 8.2.0473: variables declared in an outer scope
Bram Moolenaar <Bram@vim.org>
parents:
19609
diff
changeset
|
3812 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3813 curbuf = buf; |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3814 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
|
3815 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
|
3816 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
|
3817 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
|
3818 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
|
3819 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3820 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3821 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3822 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3823 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3824 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3825 * 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
|
3826 * 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
|
3827 * "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
|
3828 * "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
|
3829 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3830 callback_T |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3831 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
|
3832 { |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3833 callback_T res; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3834 int r = OK; |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3835 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3836 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
|
3837 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
|
3838 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3839 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
|
3840 ++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
|
3841 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
|
3842 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3843 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3844 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3845 res.cb_partial = NULL; |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3846 if (arg->v_type == VAR_STRING && arg->vval.v_string != NULL |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3847 && isdigit(*arg->vval.v_string)) |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3848 r = FAIL; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3849 else if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3850 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3851 // 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
|
3852 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
|
3853 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
|
3854 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3855 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
|
3856 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
|
3857 else |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3858 r = FAIL; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3859 |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
3860 if (r == FAIL) |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3861 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3862 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
|
3863 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
|
3864 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3865 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3866 return res; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3867 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3868 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3869 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3870 * 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
|
3871 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3872 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3873 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
|
3874 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3875 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
|
3876 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3877 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
|
3878 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
|
3879 ++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
|
3880 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3881 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3882 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3883 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
|
3884 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
|
3885 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
|
3886 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3887 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3888 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3889 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3890 * 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
|
3891 * 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
|
3892 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3893 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3894 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
|
3895 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3896 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
|
3897 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3898 // 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
|
3899 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
|
3900 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
|
3901 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3902 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3903 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3904 // 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
|
3905 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
|
3906 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
|
3907 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3908 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
|
3909 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3910 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3911 /* |
21409
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3912 * Copy callback from "src" to "dest", incrementing the refcounts. |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3913 */ |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3914 void |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3915 copy_callback(callback_T *dest, callback_T *src) |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3916 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3917 dest->cb_partial = src->cb_partial; |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3918 if (dest->cb_partial != NULL) |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3919 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3920 dest->cb_name = src->cb_name; |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3921 dest->cb_free_name = FALSE; |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3922 ++dest->cb_partial->pt_refcount; |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3923 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3924 else |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3925 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3926 dest->cb_name = vim_strsave(src->cb_name); |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3927 dest->cb_free_name = TRUE; |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3928 func_ref(src->cb_name); |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3929 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3930 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3931 |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
3932 /* |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3933 * 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
|
3934 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3935 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3936 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
|
3937 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3938 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
|
3939 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3940 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
|
3941 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
|
3942 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3943 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
|
3944 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
|
3945 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
|
3946 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3947 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
|
3948 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
|
3949 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3950 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
|
3951 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
3952 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3953 #endif // FEAT_EVAL |