Mercurial > vim
annotate src/evalvars.c @ 31853:0799b0bf5c6c v9.0.1259
patch 9.0.1259: diffmode test fails
Commit: https://github.com/vim/vim/commit/492324e58840f441d7226e7656844e778e65d7fb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 28 20:57:59 2023 +0000
patch 9.0.1259: diffmode test fails
Problem: Diffmode test fails.
Solution: Adjust expected result for adjusted indenting.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Jan 2023 22:00:03 +0100 |
parents | 2d68375d5ddf |
children | 7d505d77f6da |
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!) |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
48 type_T *vv_type; // type or NULL |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
49 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
|
50 } 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
|
51 { |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
52 // 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
|
53 // Initializing a union does not work, leave tv.vval empty to get zero's. |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
54 {VV_NAME("count", VAR_NUMBER), NULL, VV_COMPAT+VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
55 {VV_NAME("count1", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
56 {VV_NAME("prevcount", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
57 {VV_NAME("errmsg", VAR_STRING), NULL, VV_COMPAT}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
58 {VV_NAME("warningmsg", VAR_STRING), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
59 {VV_NAME("statusmsg", VAR_STRING), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
60 {VV_NAME("shell_error", VAR_NUMBER), NULL, VV_COMPAT+VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
61 {VV_NAME("this_session", VAR_STRING), NULL, VV_COMPAT}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
62 {VV_NAME("version", VAR_NUMBER), NULL, VV_COMPAT+VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
63 {VV_NAME("lnum", VAR_NUMBER), NULL, VV_RO_SBX}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
64 {VV_NAME("termresponse", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
65 {VV_NAME("fname", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
66 {VV_NAME("lang", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
67 {VV_NAME("lc_time", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
68 {VV_NAME("ctype", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
69 {VV_NAME("charconvert_from", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
70 {VV_NAME("charconvert_to", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
71 {VV_NAME("fname_in", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
72 {VV_NAME("fname_out", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
73 {VV_NAME("fname_new", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
74 {VV_NAME("fname_diff", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
75 {VV_NAME("cmdarg", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
76 {VV_NAME("foldstart", VAR_NUMBER), NULL, VV_RO_SBX}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
77 {VV_NAME("foldend", VAR_NUMBER), NULL, VV_RO_SBX}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
78 {VV_NAME("folddashes", VAR_STRING), NULL, VV_RO_SBX}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
79 {VV_NAME("foldlevel", VAR_NUMBER), NULL, VV_RO_SBX}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
80 {VV_NAME("progname", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
81 {VV_NAME("servername", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
82 {VV_NAME("dying", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
83 {VV_NAME("exception", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
84 {VV_NAME("throwpoint", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
85 {VV_NAME("register", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
86 {VV_NAME("cmdbang", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
87 {VV_NAME("insertmode", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
88 {VV_NAME("val", VAR_UNKNOWN), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
89 {VV_NAME("key", VAR_UNKNOWN), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
90 {VV_NAME("profiling", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
91 {VV_NAME("fcs_reason", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
92 {VV_NAME("fcs_choice", VAR_STRING), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
93 {VV_NAME("beval_bufnr", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
94 {VV_NAME("beval_winnr", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
95 {VV_NAME("beval_winid", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
96 {VV_NAME("beval_lnum", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
97 {VV_NAME("beval_col", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
98 {VV_NAME("beval_text", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
99 {VV_NAME("scrollstart", VAR_STRING), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
100 {VV_NAME("swapname", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
101 {VV_NAME("swapchoice", VAR_STRING), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
102 {VV_NAME("swapcommand", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
103 {VV_NAME("char", VAR_STRING), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
104 {VV_NAME("mouse_win", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
105 {VV_NAME("mouse_winid", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
106 {VV_NAME("mouse_lnum", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
107 {VV_NAME("mouse_col", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
108 {VV_NAME("operator", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
109 {VV_NAME("searchforward", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
110 {VV_NAME("hlsearch", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
111 {VV_NAME("oldfiles", VAR_LIST), &t_list_string, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
112 {VV_NAME("windowid", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
113 {VV_NAME("progpath", VAR_STRING), NULL, VV_RO}, |
29501
69d24e60f4f8
patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents:
29497
diff
changeset
|
114 {VV_NAME("completed_item", VAR_DICT), &t_dict_string, 0}, |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
115 {VV_NAME("option_new", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
116 {VV_NAME("option_old", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
117 {VV_NAME("option_oldlocal", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
118 {VV_NAME("option_oldglobal", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
119 {VV_NAME("option_command", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
120 {VV_NAME("option_type", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
121 {VV_NAME("errors", VAR_LIST), &t_list_string, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
122 {VV_NAME("false", VAR_BOOL), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
123 {VV_NAME("true", VAR_BOOL), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
124 {VV_NAME("none", VAR_SPECIAL), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
125 {VV_NAME("null", VAR_SPECIAL), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
126 {VV_NAME("numbermax", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
127 {VV_NAME("numbermin", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
128 {VV_NAME("numbersize", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
129 {VV_NAME("vim_did_enter", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
130 {VV_NAME("testing", VAR_NUMBER), NULL, 0}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
131 {VV_NAME("t_number", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
132 {VV_NAME("t_string", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
133 {VV_NAME("t_func", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
134 {VV_NAME("t_list", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
135 {VV_NAME("t_dict", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
136 {VV_NAME("t_float", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
137 {VV_NAME("t_bool", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
138 {VV_NAME("t_none", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
139 {VV_NAME("t_job", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
140 {VV_NAME("t_channel", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
141 {VV_NAME("t_blob", VAR_NUMBER), NULL, VV_RO}, |
31712
2d68375d5ddf
patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents:
31708
diff
changeset
|
142 {VV_NAME("t_class", VAR_NUMBER), NULL, VV_RO}, |
2d68375d5ddf
patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents:
31708
diff
changeset
|
143 {VV_NAME("t_object", VAR_NUMBER), NULL, VV_RO}, |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
144 {VV_NAME("termrfgresp", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
145 {VV_NAME("termrbgresp", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
146 {VV_NAME("termu7resp", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
147 {VV_NAME("termstyleresp", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
148 {VV_NAME("termblinkresp", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
149 {VV_NAME("event", VAR_DICT), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
150 {VV_NAME("versionlong", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
151 {VV_NAME("echospace", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
152 {VV_NAME("argv", VAR_LIST), &t_list_string, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
153 {VV_NAME("collate", VAR_STRING), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
154 {VV_NAME("exiting", VAR_SPECIAL), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
155 {VV_NAME("colornames", VAR_DICT), &t_dict_string, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
156 {VV_NAME("sizeofint", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
157 {VV_NAME("sizeoflong", VAR_NUMBER), NULL, VV_RO}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
158 {VV_NAME("sizeofpointer", VAR_NUMBER), NULL, VV_RO}, |
26881
fb67cd7d30a7
patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
159 {VV_NAME("maxcol", VAR_NUMBER), NULL, 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
162 // shorthand |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
163 #define vv_tv_type vv_di.di_tv.v_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
|
164 #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
|
165 #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
|
166 #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
|
167 #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
|
168 #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
|
169 #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
|
170 #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
|
171 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
172 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
|
173 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
|
174 #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
|
175 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
176 // 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
|
177 #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
|
178 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
184 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int flags, char_u *endchars, char_u *op, int var_idx); |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
185 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
|
186 static int do_lock_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 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
|
188 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
|
189 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
191 * 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
|
192 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
193 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
194 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
|
195 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
196 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
|
197 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
|
198 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 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
|
203 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
204 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
|
205 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
206 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
|
207 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
|
208 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
209 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
|
210 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
|
211 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
218 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
|
219 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
220 // add to v: scope dict, unless the value is not always available |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
221 if (p->vv_tv_type != VAR_UNKNOWN) |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
222 hash_add(&vimvarht, p->vv_di.di_key, "initialization"); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
223 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
|
224 // add to compat scope dict |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
225 hash_add(&compat_hashtab, p->vv_di.di_key, "initialization"); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
226 } |
22480
5e95de50ddd2
patch 8.2.1788: Vim9: still allows :let for declarations
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
227 set_vim_var_nr(VV_VERSION, VIM_VERSION_100); |
5e95de50ddd2
patch 8.2.1788: Vim9: still allows :let for declarations
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
228 set_vim_var_nr(VV_VERSIONLONG, VIM_VERSION_100 * 10000 + highest_patch()); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
229 |
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_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
|
231 set_vim_var_nr(VV_HLSEARCH, 1L); |
23048
ad674a98058a
patch 8.2.2070: can't get the exit value in VimLeave(Pre) autocommands
Bram Moolenaar <Bram@vim.org>
parents:
22942
diff
changeset
|
232 set_vim_var_nr(VV_EXITING, VVAL_NULL); |
17885
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_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
|
234 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
|
235 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
|
236 |
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_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
|
238 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
|
239 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
|
240 set_vim_var_nr(VV_NULL, VVAL_NULL); |
23693
cd06cc37f53f
patch 8.2.2388: no easy way to get the maximum or mininum number value
Bram Moolenaar <Bram@vim.org>
parents:
23679
diff
changeset
|
241 set_vim_var_nr(VV_NUMBERMAX, VARNUM_MAX); |
cd06cc37f53f
patch 8.2.2388: no easy way to get the maximum or mininum number value
Bram Moolenaar <Bram@vim.org>
parents:
23679
diff
changeset
|
242 set_vim_var_nr(VV_NUMBERMIN, VARNUM_MIN); |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
243 set_vim_var_nr(VV_NUMBERSIZE, sizeof(varnumber_T) * 8); |
26079
a60952e58e5d
patch 8.2.3573: cannot decide whether to skip test that fails with 64 bit
Bram Moolenaar <Bram@vim.org>
parents:
26057
diff
changeset
|
244 set_vim_var_nr(VV_SIZEOFINT, sizeof(int)); |
a60952e58e5d
patch 8.2.3573: cannot decide whether to skip test that fails with 64 bit
Bram Moolenaar <Bram@vim.org>
parents:
26057
diff
changeset
|
245 set_vim_var_nr(VV_SIZEOFLONG, sizeof(long)); |
a60952e58e5d
patch 8.2.3573: cannot decide whether to skip test that fails with 64 bit
Bram Moolenaar <Bram@vim.org>
parents:
26057
diff
changeset
|
246 set_vim_var_nr(VV_SIZEOFPOINTER, sizeof(char *)); |
26881
fb67cd7d30a7
patch 8.2.3969: value of MAXCOL not available in Vim script
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
247 set_vim_var_nr(VV_MAXCOL, MAXCOL); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
248 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
249 set_vim_var_nr(VV_TYPE_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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 set_vim_var_nr(VV_TYPE_BLOB, VAR_TYPE_BLOB); |
31712
2d68375d5ddf
patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents:
31708
diff
changeset
|
260 set_vim_var_nr(VV_TYPE_CLASS, VAR_TYPE_CLASS); |
2d68375d5ddf
patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents:
31708
diff
changeset
|
261 set_vim_var_nr(VV_TYPE_OBJECT, VAR_TYPE_OBJECT); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
262 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
263 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
|
264 |
26057
92c424550367
patch 8.2.3562: cannot add color names
Bram Moolenaar <Bram@vim.org>
parents:
25955
diff
changeset
|
265 set_vim_var_dict(VV_COLORNAMES, dict_alloc()); |
92c424550367
patch 8.2.3562: cannot add color names
Bram Moolenaar <Bram@vim.org>
parents:
25955
diff
changeset
|
266 |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
267 // 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
|
268 // 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
|
269 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
|
270 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
271 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
272 #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
|
273 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
274 * 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
|
275 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
276 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
277 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
|
278 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
279 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
|
280 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
|
281 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
282 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
|
283 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 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
|
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 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
|
290 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
|
291 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
292 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
297 // 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
|
298 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
|
299 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
300 // 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
|
301 // 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
|
302 // 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
|
303 // another script. |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
304 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
|
305 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
|
306 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
307 #endif |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
308 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
309 int |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
310 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
|
311 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
312 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
|
313 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
314 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
315 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
|
316 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
|
317 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
318 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
321 int |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
322 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
|
323 { |
22602
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
324 int i; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
325 int idx; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
326 int abort = FALSE; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
327 scriptitem_T *si; |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
328 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
329 for (i = 1; i <= script_items.ga_len; ++i) |
22602
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
330 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
331 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
|
332 |
22602
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
333 si = SCRIPT_ITEM(i); |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
334 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx) |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
335 { |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
336 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
337 |
24075
c5e396fb0ebe
patch 8.2.2579: Vim9: crash in garbagecollect after for loop
Bram Moolenaar <Bram@vim.org>
parents:
24051
diff
changeset
|
338 if (sv->sv_name != NULL) |
c5e396fb0ebe
patch 8.2.2579: Vim9: crash in garbagecollect after for loop
Bram Moolenaar <Bram@vim.org>
parents:
24051
diff
changeset
|
339 abort = abort || set_ref_in_item(sv->sv_tv, copyID, NULL, NULL); |
22602
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
340 } |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
341 } |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
342 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
343 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
|
344 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
345 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
346 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
347 * 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
|
348 * 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
|
349 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
350 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
351 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
|
352 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
353 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
|
354 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
|
355 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
356 val = vim_strsave(value); |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
357 if (val == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
358 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
359 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
360 tvp = alloc_string_tv(val); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
361 if (tvp == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
362 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
363 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
364 set_var(name, tvp, FALSE); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
365 free_tv(tvp); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
366 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
367 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
368 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
369 eval_charconvert( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
370 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
|
371 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
|
372 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
|
373 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
|
374 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
375 int err = FALSE; |
27330
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
376 sctx_T saved_sctx = current_sctx; |
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
377 sctx_T *ctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
378 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 set_vim_var_string(VV_FNAME_OUT, fname_to, -1); |
27330
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
383 ctx = get_option_sctx("charconvert"); |
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
384 if (ctx != NULL) |
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
385 current_sctx = *ctx; |
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
386 |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
387 if (eval_to_bool(p_ccv, &err, NULL, FALSE, TRUE)) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
388 err = TRUE; |
27330
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
389 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
390 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
|
391 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
|
392 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
|
393 set_vim_var_string(VV_FNAME_OUT, NULL, -1); |
27330
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
394 current_sctx = saved_sctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
395 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
396 if (err) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
397 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
398 return OK; |
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 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
401 # 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
|
402 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
403 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
|
404 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
405 int err = FALSE; |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
406 sctx_T saved_sctx = current_sctx; |
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
407 sctx_T *ctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
408 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
409 set_vim_var_string(VV_FNAME_IN, fname, -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_CMDARG, args, -1); |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
411 ctx = get_option_sctx("printexpr"); |
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
412 if (ctx != NULL) |
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
413 current_sctx = *ctx; |
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
414 |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
415 if (eval_to_bool(p_pexpr, &err, NULL, FALSE, TRUE)) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
416 err = TRUE; |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
417 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
418 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
|
419 set_vim_var_string(VV_CMDARG, NULL, -1); |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
420 current_sctx = saved_sctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
421 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
422 if (err) |
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 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
|
425 return FAIL; |
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 return OK; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
428 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
429 # endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
430 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
431 # 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
|
432 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
433 eval_diff( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 { |
27305
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
438 sctx_T saved_sctx = current_sctx; |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
439 sctx_T *ctx; |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
440 typval_T *tv; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
441 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
442 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
|
443 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
|
444 set_vim_var_string(VV_FNAME_OUT, outfile, -1); |
27305
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
445 |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
446 ctx = get_option_sctx("diffexpr"); |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
447 if (ctx != NULL) |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
448 current_sctx = *ctx; |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
449 |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
450 // errors are ignored |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
451 tv = eval_expr_ext(p_dex, NULL, TRUE); |
27307
bb36a04d7e34
patch 8.2.4182: memory leak when evaluating 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27305
diff
changeset
|
452 free_tv(tv); |
27305
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
453 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
454 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
|
455 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
|
456 set_vim_var_string(VV_FNAME_OUT, NULL, -1); |
27305
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
457 current_sctx = saved_sctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
458 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
459 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
460 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
461 eval_patch( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 { |
27315
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
466 sctx_T saved_sctx = current_sctx; |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
467 sctx_T *ctx; |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
468 typval_T *tv; |
17922
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 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
|
471 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
|
472 set_vim_var_string(VV_FNAME_OUT, outfile, -1); |
27315
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
473 |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
474 ctx = get_option_sctx("patchexpr"); |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
475 if (ctx != NULL) |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
476 current_sctx = *ctx; |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
477 |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
478 // errors are ignored |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
479 tv = eval_expr_ext(p_pex, NULL, TRUE); |
27315
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
480 free_tv(tv); |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
481 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
482 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
|
483 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
|
484 set_vim_var_string(VV_FNAME_OUT, NULL, -1); |
27315
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
485 current_sctx = saved_sctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
486 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
487 # endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
488 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
489 #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
|
490 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
491 * 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
|
492 * 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
|
493 * 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
|
494 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
495 list_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
496 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
|
497 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 char_u *p = skipwhite(expr); |
27338
c62006deb5c1
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest'
Bram Moolenaar <Bram@vim.org>
parents:
27330
diff
changeset
|
502 sctx_T saved_sctx = current_sctx; |
c62006deb5c1
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest'
Bram Moolenaar <Bram@vim.org>
parents:
27330
diff
changeset
|
503 sctx_T *ctx; |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
504 int r; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
505 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
506 // 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
|
507 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
|
508 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
|
509 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
|
510 ++emsg_off; |
27338
c62006deb5c1
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest'
Bram Moolenaar <Bram@vim.org>
parents:
27330
diff
changeset
|
511 ctx = get_option_sctx("spellsuggest"); |
c62006deb5c1
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest'
Bram Moolenaar <Bram@vim.org>
parents:
27330
diff
changeset
|
512 if (ctx != NULL) |
c62006deb5c1
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest'
Bram Moolenaar <Bram@vim.org>
parents:
27330
diff
changeset
|
513 current_sctx = *ctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
514 |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
515 r = may_call_simple_func(p, &rettv); |
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
516 if (r == NOTDONE) |
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
517 r = eval1(&p, &rettv, &EVALARG_EVALUATE); |
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
518 if (r == OK) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
519 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
520 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
|
521 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
|
522 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
523 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
|
524 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
525 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
526 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
|
527 --emsg_off; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
528 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
|
529 restore_vimvar(VV_VAL, &save_val); |
27338
c62006deb5c1
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest'
Bram Moolenaar <Bram@vim.org>
parents:
27330
diff
changeset
|
530 current_sctx = saved_sctx; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
531 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
532 return list; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
533 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
534 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
535 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
536 * "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
|
537 * 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
|
538 * 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
|
539 * 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
|
540 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
541 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
542 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
|
543 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
544 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
|
545 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
546 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
|
547 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
|
548 return -1; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
549 *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
|
550 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
551 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
|
552 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
|
553 return -1; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
554 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
|
555 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
556 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
557 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
558 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
559 * 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
|
560 * 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
|
561 * 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
|
562 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
563 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
564 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
|
565 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
566 *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
|
567 vimvars[idx].vv_str = NULL; // don't free it now |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
568 if (vimvars[idx].vv_tv_type == VAR_UNKNOWN) |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
569 hash_add(&vimvarht, vimvars[idx].vv_di.di_key, "prepare vimvar"); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
570 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
571 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
572 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
573 * 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
|
574 * 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
|
575 * 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
|
576 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
577 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
578 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
|
579 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
580 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
|
581 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
582 vimvars[idx].vv_tv = *save_tv; |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
583 if (vimvars[idx].vv_tv_type != VAR_UNKNOWN) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
584 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
585 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
586 hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
587 if (HASHITEM_EMPTY(hi)) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
588 internal_error("restore_vimvar()"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
589 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
590 hash_remove(&vimvarht, hi, "restore vimvar"); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
591 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
592 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
593 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
594 * 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
|
595 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
596 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
|
597 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
|
598 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
599 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
|
600 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
601 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
602 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
603 * 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
|
604 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
605 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
|
606 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
|
607 { |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21955
diff
changeset
|
608 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
|
609 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
|
610 "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
|
611 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
612 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
613 /* |
30217
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
614 * Return TRUE if "name" starts with "g:", "w:", "t:" or "b:". |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
615 * But only when an identifier character follows. |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
616 */ |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
617 int |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
618 is_scoped_variable(char_u *name) |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
619 { |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
620 return vim_strchr((char_u *)"gwbt", name[0]) != NULL |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
621 && name[1] == ':' |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
622 && eval_isnamec(name[2]); |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
623 } |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
624 |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
625 /* |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
626 * Evaluate one Vim expression {expr} in string "p" and append the |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
627 * resulting string to "gap". "p" points to the opening "{". |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
628 * When "evaluate" is FALSE only skip over the expression. |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
629 * Return a pointer to the character after "}", NULL for an error. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
630 */ |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
631 char_u * |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
632 eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate) |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
633 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
634 char_u *block_start = skipwhite(p + 1); // skip the opening { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
635 char_u *block_end = block_start; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
636 char_u *expr_val; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
637 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
638 if (*block_start == NUL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
639 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
640 semsg(_(e_missing_close_curly_str), p); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
641 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
642 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
643 if (skip_expr(&block_end, NULL) == FAIL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
644 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
645 block_end = skipwhite(block_end); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
646 if (*block_end != '}') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
647 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
648 semsg(_(e_missing_close_curly_str), p); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
649 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
650 } |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
651 if (evaluate) |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
652 { |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
653 *block_end = NUL; |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
654 expr_val = eval_to_string(block_start, TRUE, FALSE); |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
655 *block_end = '}'; |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
656 if (expr_val == NULL) |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
657 return NULL; |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
658 ga_concat(gap, expr_val); |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
659 vim_free(expr_val); |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
660 } |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
661 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
662 return block_end + 1; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
663 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
664 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
665 /* |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
666 * Evaluate all the Vim expressions {expr} in "str" and return the resulting |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
667 * string in allocated memory. "{{" is reduced to "{" and "}}" to "}". |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
668 * Used for a heredoc assignment. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
669 * Returns NULL for an error. |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
670 */ |
29320
a74398c432a4
patch 9.0.0003: functions are global while they could be local
Bram Moolenaar <Bram@vim.org>
parents:
28990
diff
changeset
|
671 static char_u * |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
672 eval_all_expr_in_str(char_u *str) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
673 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
674 garray_T ga; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
675 char_u *p; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
676 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
677 ga_init2(&ga, 1, 80); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
678 p = str; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
679 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
680 while (*p != NUL) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
681 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
682 char_u *lit_start; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
683 int escaped_brace = FALSE; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
684 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
685 // Look for a block start. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
686 lit_start = p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
687 while (*p != '{' && *p != '}' && *p != NUL) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
688 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
689 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
690 if (*p != NUL && *p == p[1]) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
691 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
692 // Escaped brace, unescape and continue. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
693 // Include the brace in the literal string. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
694 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
695 escaped_brace = TRUE; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
696 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
697 else if (*p == '}') |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
698 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
699 semsg(_(e_stray_closing_curly_str), str); |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
700 ga_clear(&ga); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
701 return NULL; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
702 } |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
703 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
704 // Append the literal part. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
705 ga_concat_len(&ga, lit_start, (size_t)(p - lit_start)); |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
706 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
707 if (*p == NUL) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
708 break; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
709 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
710 if (escaped_brace) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
711 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
712 // Skip the second brace. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
713 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
714 continue; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
715 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
716 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
717 // Evaluate the expression and append the result. |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
718 p = eval_one_expr_in_str(p, &ga, TRUE); |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
719 if (p == NULL) |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
720 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
721 ga_clear(&ga); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
722 return NULL; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
723 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
724 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
725 ga_append(&ga, NUL); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
726 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
727 return ga.ga_data; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
728 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
729 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
730 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 * 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
|
732 * 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
|
733 * cmd << {marker} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 * {line1} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 * {line2} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 * .... |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 * {marker} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 * 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
|
740 * marker, then the leading indentation before the lines (matching the |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
741 * 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
|
742 * |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
743 * When getting lines for an embedded script (e.g. python, lua, perl, ruby, |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
744 * tcl, mzscheme), "script_get" is set to TRUE. In this case, if the marker is |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
745 * 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
|
746 * |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
747 * When compiling a heredoc assignment to a variable in a Vim9 def function, |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
748 * "vim9compile" is set to TRUE. In this case, instead of generating a list of |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
749 * string values from the heredoc, vim9 instructions are generated. On success |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
750 * the returned list will be empty. |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
751 * |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
752 * Returns a List with {lines} or NULL on failure. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
754 list_T * |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
755 heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 { |
28518
1a2643893aa4
patch 8.2.4783: Coverity warns for leaking memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
757 char_u *theline = NULL; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 char_u *marker; |
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 char_u *p; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
761 char_u *str; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 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
|
763 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
|
764 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
|
765 char_u dot[] = "."; |
22413
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22409
diff
changeset
|
766 int comment_char = in_vim9script() ? '#' : '"'; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
767 int evalstr = FALSE; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
768 int eval_failed = FALSE; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
769 cctx_T *cctx = vim9compile ? eap->cookie : NULL; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
770 int count = 0; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 if (eap->getline == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
774 emsg(_(e_cannot_use_heredoc_here)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 // 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
|
779 cmd = skipwhite(cmd); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
780 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
781 while (TRUE) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 { |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
783 if (STRNCMP(cmd, "trim", 4) == 0 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
784 && (cmd[4] == NUL || VIM_ISWHITE(cmd[4]))) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 { |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
786 cmd = skipwhite(cmd + 4); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
787 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
788 // Trim the indentation from all the lines in the here document. |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
789 // The amount of indentation trimmed is the same as the indentation |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
790 // of the first line after the :let command line. To find the end |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
791 // marker the indent of the :let command line is trimmed. |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
792 p = *eap->cmdlinep; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
793 while (VIM_ISWHITE(*p)) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
794 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
795 p++; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
796 marker_indent_len++; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
797 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
798 text_indent_len = -1; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
799 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
800 continue; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 } |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
802 if (STRNCMP(cmd, "eval", 4) == 0 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
803 && (cmd[4] == NUL || VIM_ISWHITE(cmd[4]))) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
804 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
805 cmd = skipwhite(cmd + 4); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
806 evalstr = TRUE; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
807 continue; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
808 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
809 break; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 // The marker is the next word. |
22413
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22409
diff
changeset
|
813 if (*cmd != NUL && *cmd != comment_char) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 marker = skipwhite(cmd); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 p = skiptowhite(marker); |
22413
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22409
diff
changeset
|
817 if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
819 semsg(_(e_trailing_characters_str), p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 *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
|
823 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
|
824 { |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
825 emsg(_(e_marker_cannot_start_with_lower_case_letter)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 { |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
831 // 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
|
832 // 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
|
833 if (script_get) |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
834 marker = dot; |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
835 else |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
836 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26723
diff
changeset
|
837 emsg(_(e_missing_marker)); |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
838 return NULL; |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
839 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 l = list_alloc(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 if (l == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 return NULL; |
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 for (;;) |
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 int mi = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 int ti = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 |
28518
1a2643893aa4
patch 8.2.4783: Coverity warns for leaking memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
851 vim_free(theline); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 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
|
853 if (theline == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
855 semsg(_(e_missing_end_marker_str), marker); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 // 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
|
860 // marker |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 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
|
862 && 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
|
863 mi = marker_indent_len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 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
|
865 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
867 // If expression evaluation failed in the heredoc, then skip till the |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
868 // end marker. |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
869 if (eval_failed) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
870 continue; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
871 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 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
|
873 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 // 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
|
875 p = theline; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 text_indent_len = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 while (VIM_ISWHITE(*p)) |
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 p++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 text_indent_len++; |
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 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
|
883 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 // 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
|
885 if (text_indent != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 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
|
887 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
|
888 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
890 str = theline + ti; |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
891 if (vim9compile) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
892 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
893 if (compile_all_expr_in_str(str, evalstr, cctx) == FAIL) |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
894 { |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
895 vim_free(theline); |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
896 vim_free(text_indent); |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
897 return FAIL; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
898 } |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
899 count++; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
900 } |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
901 else |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
902 { |
28633
7a39c20a42fa
patch 8.2.4840: heredoc expression evaluated even when skipping
Bram Moolenaar <Bram@vim.org>
parents:
28560
diff
changeset
|
903 if (evalstr && !eap->skip) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
904 { |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
905 str = eval_all_expr_in_str(str); |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
906 if (str == NULL) |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
907 { |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
908 // expression evaluation failed |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
909 eval_failed = TRUE; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
910 continue; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
911 } |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
912 vim_free(theline); |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
913 theline = str; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
914 } |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
915 |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
916 if (list_append_string(l, str, -1) == FAIL) |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
917 break; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
918 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 } |
28518
1a2643893aa4
patch 8.2.4783: Coverity warns for leaking memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
920 vim_free(theline); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 vim_free(text_indent); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
923 if (vim9compile && cctx->ctx_skip != SKIP_YES && !eval_failed) |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
924 generate_NEWLIST(cctx, count, FALSE); |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
925 |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
926 if (eval_failed) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
927 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
928 // expression evaluation in the heredoc failed |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
929 list_free(l); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
930 return NULL; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
931 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 return l; |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 /* |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
936 * Vim9 variable declaration: |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
937 * ":var name" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
938 * ":var name: type" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
939 * ":var name = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
940 * ":var name: type = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
941 * etc. |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
942 */ |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
943 void |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
944 ex_var(exarg_T *eap) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
945 { |
27966
80f398bfc19f
patch 8.2.4508: Vim9: cannot assign to a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27950
diff
changeset
|
946 char_u *p = eap->cmd; |
27968
40c6e5f849dc
patch 8.2.4509: Vim9: can declare a variable with ":va"
Bram Moolenaar <Bram@vim.org>
parents:
27966
diff
changeset
|
947 int has_var; |
27966
80f398bfc19f
patch 8.2.4508: Vim9: cannot assign to a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27950
diff
changeset
|
948 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
949 if (!in_vim9script()) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
950 { |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
951 semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var"); |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
952 return; |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
953 } |
27968
40c6e5f849dc
patch 8.2.4509: Vim9: can declare a variable with ":va"
Bram Moolenaar <Bram@vim.org>
parents:
27966
diff
changeset
|
954 has_var = checkforcmd_noparen(&p, "var", 3); |
40c6e5f849dc
patch 8.2.4509: Vim9: can declare a variable with ":va"
Bram Moolenaar <Bram@vim.org>
parents:
27966
diff
changeset
|
955 if (current_sctx.sc_sid == 0 && has_var) |
27950
aacc98a38cf3
patch 8.2.4500: Vim9: can declare a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27934
diff
changeset
|
956 { |
aacc98a38cf3
patch 8.2.4500: Vim9: can declare a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27934
diff
changeset
|
957 emsg(_(e_cannot_declare_variable_on_command_line)); |
aacc98a38cf3
patch 8.2.4500: Vim9: can declare a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27934
diff
changeset
|
958 return; |
aacc98a38cf3
patch 8.2.4500: Vim9: can declare a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27934
diff
changeset
|
959 } |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
960 ex_let(eap); |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
961 } |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
962 |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
963 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 * ":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
|
965 * ":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
|
966 * ":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
|
967 * ":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
|
968 * ":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
|
969 * ":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
|
970 * ":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
|
971 * ":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
|
972 * ":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
|
973 * ":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
|
974 * ":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
|
975 * ":let var =<< ..." heredoc |
19524
4a6a412e4565
patch 8.2.0319: file missing in distribution, comments outdated
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
976 * ":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
|
977 * |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
978 * ":final var = expr" assignment command. |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
979 * ":final [var1, var2] = expr" unpack list. |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
980 * |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 * ":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
|
982 * ":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
|
983 * ":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
|
984 * ":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
|
985 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 void |
20536
8fa783f2c69c
patch 8.2.0822: Vim9: code left over from discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20530
diff
changeset
|
987 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
|
988 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 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
|
990 char_u *expr = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 typval_T rettv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 int i; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 int var_count = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 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
|
995 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
|
996 char_u *argend; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 int first = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 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
|
999 int has_assign; |
23297
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1000 int flags = 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
|
1001 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
|
1002 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1003 if (eap->cmdidx == CMD_final && !vim9script) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1004 { |
23297
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1005 // In legacy Vim script ":final" is short for ":finally". |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1006 ex_finally(eap); |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1007 return; |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1008 } |
22667
87987c783087
patch 8.2.1882: Vim9: v:disallow_let is no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
22602
diff
changeset
|
1009 if (eap->cmdidx == CMD_let && vim9script) |
22415
1cefe1c013ac
patch 8.2.1756: Vim9: :let will soon be disallowed
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
1010 { |
1cefe1c013ac
patch 8.2.1756: Vim9: :let will soon be disallowed
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
1011 emsg(_(e_cannot_use_let_in_vim9_script)); |
1cefe1c013ac
patch 8.2.1756: Vim9: :let will soon be disallowed
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
1012 return; |
1cefe1c013ac
patch 8.2.1756: Vim9: :let will soon be disallowed
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
1013 } |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1014 |
23297
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1015 if (eap->cmdidx == CMD_const) |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1016 flags |= ASSIGN_CONST; |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1017 else if (eap->cmdidx == CMD_final) |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1018 flags |= ASSIGN_FINAL; |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1019 |
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1020 // Vim9 assignment without ":let", ":const" or ":final" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1021 if (eap->arg == eap->cmd) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1022 flags |= ASSIGN_NO_DECL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1023 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1024 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
|
1025 if (argend == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 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
|
1028 --argend; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 expr = skipwhite(argend); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 concat = expr[0] == '.' |
25622
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25613
diff
changeset
|
1031 && ((expr[1] == '=' && in_old_script(2)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 || (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
|
1033 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
|
1034 && 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
|
1035 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
|
1036 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 // ":let" without "=": list variables |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 if (*arg == '[') |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1039 emsg(_(e_invalid_argument)); |
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
|
1040 else if (expr[0] == '.' && expr[1] == '=') |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1041 emsg(_(e_dot_equal_not_supported_with_script_version_two)); |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20103
diff
changeset
|
1042 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
|
1043 { |
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
|
1044 if (vim9script) |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1045 { |
24238
e5cd25f7ffcd
patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1046 if (!ends_excmd2(eap->cmd, skipwhite(argend))) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
1047 semsg(_(e_trailing_characters_str), argend); |
24238
e5cd25f7ffcd
patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1048 else |
e5cd25f7ffcd
patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1049 // Vim9 declaration ":var name: type" |
e5cd25f7ffcd
patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1050 arg = vim9_declare_scriptvar(eap, arg); |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1051 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1052 else |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1053 { |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1054 // ":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
|
1055 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
|
1056 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1057 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 else if (!eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 // ":let" |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 list_glob_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 list_buf_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 list_win_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 list_tab_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 list_script_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 list_func_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 list_vim_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
1069 set_nextcmd(eap, arg); |
17873
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 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
|
1072 { |
30795
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1073 list_T *l = NULL; |
25405
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
1074 long cur_lnum = SOURCING_LNUM; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 |
30795
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1076 // :let text =<< [trim] [eval] END |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1077 // :var text =<< [trim] [eval] END |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1078 if (vim9script && !eap->skip && (!VIM_ISWHITE(expr[-1]) |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1079 || !IS_WHITE_OR_NUL(expr[3]))) |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1080 semsg(_(e_white_space_required_before_and_after_str_at_str), |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1081 "=<<", expr); |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1082 else |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1083 l = heredoc_get(eap, expr + 3, FALSE, FALSE); |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1084 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 if (l != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 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
|
1088 if (!eap->skip) |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1089 { |
25405
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
1090 // errors are for the assignment, not the end marker |
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
1091 SOURCING_LNUM = cur_lnum; |
18348
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1092 op[0] = '='; |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1093 op[1] = NUL; |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1094 (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
|
1095 flags, op); |
18348
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1096 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 } |
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 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1102 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
|
1103 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
|
1104 |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22027
diff
changeset
|
1105 CLEAR_FIELD(rettv); |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1106 i = FAIL; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1107 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
|
1108 { |
23707
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1109 int cur_lnum; |
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1110 |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1111 op[0] = '='; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1112 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
|
1113 if (*expr != '=') |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 { |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1115 if (vim9script && (flags & ASSIGN_NO_DECL) == 0) |
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
|
1116 { |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
1117 // +=, /=, etc. require an existing variable |
31602
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31600
diff
changeset
|
1118 semsg(_(e_cannot_use_operator_on_new_variable_str), |
53c3df37a2b0
patch 9.0.1133: error message names do not match the items
Bram Moolenaar <Bram@vim.org>
parents:
31600
diff
changeset
|
1119 eap->arg); |
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
|
1120 } |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
1121 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
|
1122 { |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1123 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
|
1124 ++len; |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1125 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
|
1126 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1127 ++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
|
1128 ++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
|
1129 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1130 } |
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
|
1131 expr += 2; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1133 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
|
1134 ++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
|
1135 |
26330
55e658312376
patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents:
26317
diff
changeset
|
1136 if (vim9script && !eap->skip && (!VIM_ISWHITE(*argend) |
21548
4e679db1c404
patch 8.2.1324: Vim9: line break after "=" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
1137 || !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
|
1138 { |
369cde0d5771
patch 8.2.1274: Vim9: no error for missing white space at script level
Bram Moolenaar <Bram@vim.org>
parents:
21409
diff
changeset
|
1139 vim_strncpy(op, expr - len, len); |
23446
b1dbbc81a011
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents:
23438
diff
changeset
|
1140 semsg(_(e_white_space_required_before_and_after_str_at_str), |
b1dbbc81a011
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents:
23438
diff
changeset
|
1141 op, argend); |
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
|
1142 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1143 |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1144 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
|
1145 ++emsg_skip; |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25348
diff
changeset
|
1146 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
21548
4e679db1c404
patch 8.2.1324: Vim9: line break after "=" does not work
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
1147 expr = skipwhite_and_linebreak(expr, &evalarg); |
23707
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1148 cur_lnum = SOURCING_LNUM; |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
1149 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
|
1150 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
|
1151 --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
|
1152 clear_evalarg(&evalarg, eap); |
23707
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1153 |
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1154 // Restore the line number so that any type error is given for the |
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1155 // declaration, not the expression. |
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1156 SOURCING_LNUM = cur_lnum; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 if (eap->skip) |
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 (i != FAIL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
1163 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
|
1164 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 (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
|
1166 flags, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 /* |
24051
da8347e453b4
patch 8.2.2567: Vim9: no error if variable is defined for existing function
Bram Moolenaar <Bram@vim.org>
parents:
24049
diff
changeset
|
1173 * Assign the typeval "tv" to the variable or variables at "arg_start". |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 * 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
|
1175 * 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
|
1176 * 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
|
1177 * or concatenate. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 * Returns OK or FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 ex_let_vars( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 char_u *arg_start, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 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
|
1185 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
|
1186 int var_count, // from skip_var_list() |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
1187 int flags, // ASSIGN_FINAL, ASSIGN_CONST, etc. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 char_u *op) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 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
|
1191 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 int i; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1193 int var_idx = 0; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 listitem_T *item; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 typval_T ltv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1197 if (tv->v_type == VAR_VOID) |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1198 { |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1199 emsg(_(e_cannot_use_void_value)); |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1200 return FAIL; |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1201 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 if (*arg != '[') |
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 // ":let var = expr" or ":for var in list" |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1205 if (ex_let_one(arg, tv, copy, flags, op, op, var_idx) == NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 // ":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
|
1211 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
|
1212 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1213 emsg(_(e_list_required)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 i = list_len(l); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 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
|
1219 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1220 emsg(_(e_less_targets_than_list_items)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 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
|
1224 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1225 emsg(_(e_more_targets_than_list_items)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1229 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
|
1230 item = l->lv_first; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 while (*arg != ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 arg = skipwhite(arg + 1); |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1234 ++var_idx; |
24426
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
1235 arg = ex_let_one(arg, &item->li_tv, TRUE, |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
1236 flags | ASSIGN_UNPACK, (char_u *)",;]", op, var_idx); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 item = item->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 if (arg == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 return FAIL; |
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 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 if (*arg == ';') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 // 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
|
1245 // 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
|
1246 l = list_alloc(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 if (l == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 while (item != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 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
|
1252 item = item->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 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
|
1256 ltv.v_lock = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 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
|
1258 l->lv_refcount = 1; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1259 ++var_idx; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 |
24426
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
1261 arg = ex_let_one(skipwhite(arg + 1), <v, FALSE, |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
1262 flags | ASSIGN_UNPACK, (char_u *)"]", op, var_idx); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 clear_tv(<v); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 if (arg == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 break; |
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 else if (*arg != ',' && *arg != ']') |
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 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
|
1271 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 } |
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 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 * 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
|
1280 * 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
|
1281 * 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
|
1282 * 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
|
1283 * 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
|
1284 * 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
|
1285 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 skip_var_list( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 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
|
1289 int include_type, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 int *var_count, |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1291 int *semicolon, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1292 int silent) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 char_u *p, *s; |
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 if (*arg == '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1297 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 // "[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
|
1299 p = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 for (;;) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 p = skipwhite(p + 1); // skip whites after '[', ';' or ',' |
23658
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1303 s = skip_var_one(p, include_type); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 if (s == p) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1306 if (!silent) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1307 semsg(_(e_invalid_argument_str), p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 return NULL; |
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 ++*var_count; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 p = skipwhite(s); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 if (*p == ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 else if (*p == ';') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 if (*semicolon == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 { |
27738
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
1319 if (!silent) |
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
1320 emsg(_(e_double_semicolon_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
|
1321 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 *semicolon = 1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 else if (*p != ',') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1327 if (!silent) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1328 semsg(_(e_invalid_argument_str), p); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 return p + 1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 } |
30819
d50d32026617
patch 9.0.0744: in script in autoload dir exported variable is not found
Bram Moolenaar <Bram@vim.org>
parents:
30795
diff
changeset
|
1334 |
30399
7fc27d7ce3b0
patch 9.0.0535: closure gets wrong value in for loop with two loop variables
Bram Moolenaar <Bram@vim.org>
parents:
30249
diff
changeset
|
1335 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
|
1336 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 * 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
|
1340 * 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
|
1341 * 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
|
1342 */ |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1343 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
|
1344 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
|
1345 { |
23660
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1346 char_u *end; |
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1347 int vim9 = 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
|
1348 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 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
|
1350 return arg + 2; |
31111
f1cb6b4dbf72
patch 9.0.0890: no test for what patch 9.0.0827 fixes
Bram Moolenaar <Bram@vim.org>
parents:
30819
diff
changeset
|
1351 |
f1cb6b4dbf72
patch 9.0.0890: no test for what patch 9.0.0827 fixes
Bram Moolenaar <Bram@vim.org>
parents:
30819
diff
changeset
|
1352 // termcap option name may have non-alpha characters |
f1cb6b4dbf72
patch 9.0.0890: no test for what patch 9.0.0827 fixes
Bram Moolenaar <Bram@vim.org>
parents:
30819
diff
changeset
|
1353 if (STRNCMP(arg, "&t_", 3) == 0 && arg[3] != NUL && arg[4] != NUL) |
f1cb6b4dbf72
patch 9.0.0890: no test for what patch 9.0.0827 fixes
Bram Moolenaar <Bram@vim.org>
parents:
30819
diff
changeset
|
1354 return arg + 5; |
f1cb6b4dbf72
patch 9.0.0890: no test for what patch 9.0.0827 fixes
Bram Moolenaar <Bram@vim.org>
parents:
30819
diff
changeset
|
1355 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1356 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
|
1357 NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); |
23658
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1358 |
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1359 // "a: type" is declaring variable "a" with a type, not "a:". |
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1360 // Same for "s: type". |
23660
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1361 if (vim9 && end == arg + 2 && end[-1] == ':') |
23658
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1362 --end; |
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1363 |
23660
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1364 if (include_type && vim9) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1365 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1366 if (*end == ':') |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
1367 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
|
1368 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1369 return end; |
17873
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 * 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
|
1374 * 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
|
1375 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 list_hashtable_vars( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 hashtab_T *ht, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 char *prefix, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 int empty, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 int *first) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 char_u buf[IOSIZE]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1388 int save_ht_flags = ht->ht_flags; |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1389 ht->ht_flags |= HTFLAGS_FROZEN; |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1390 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 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
|
1392 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
|
1393 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 --todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 di = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 // 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
|
1400 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
|
1401 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
|
1402 if (message_filtered(buf)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 continue; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 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
|
1406 || 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
|
1407 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
|
1408 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 } |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1410 |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1411 ht->ht_flags = save_ht_flags; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 |
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 * List global variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 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
|
1419 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 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
|
1421 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 * List buffer variables. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 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
|
1428 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 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
|
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 * List window variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 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
|
1437 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 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
|
1439 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 * List tab page variables. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 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
|
1446 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 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
|
1448 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 * List variables in "arg". |
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 static char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 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
|
1455 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 int error = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 int len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 char_u *name_start; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 char_u *arg_subsc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 typval_T tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20103
diff
changeset
|
1464 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
|
1465 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 if (error || eap->skip) |
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 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
|
1469 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
|
1470 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 emsg_severe = TRUE; |
25613
994cad298596
patch 8.2.3343: Vim9: autoload test fails
Bram Moolenaar <Bram@vim.org>
parents:
25611
diff
changeset
|
1472 if (!did_emsg) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
1473 semsg(_(e_trailing_characters_str), arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 // 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
|
1480 name_start = name = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 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
|
1482 if (len <= 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 // 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
|
1485 // 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
|
1486 if (len < 0 && !aborting()) |
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 emsg_severe = TRUE; |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1489 semsg(_(e_invalid_argument_str), arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
1496 arg = skipwhite(arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 if (tofree != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 name = tofree; |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
1499 if (eval_variable(name, len, 0, &tv, NULL, |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
1500 EVAL_VAR_VERBOSE) == FAIL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 // 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
|
1505 arg_subsc = arg; |
26990
4b8d836db103
patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
1506 if (handle_subscript(&arg, name_start, &tv, |
4b8d836db103
patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
1507 &EVALARG_EVALUATE, TRUE) == FAIL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 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
|
1512 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 switch (*name) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 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
|
1516 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
|
1517 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
|
1518 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
|
1519 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
|
1520 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
|
1521 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
|
1522 default: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1523 semsg(_(e_cant_list_variables_for_str), name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 char_u numbuf[NUMBUFLEN]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 char_u *tf; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 int c; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 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
|
1534 c = *arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 *arg = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 list_one_var_a("", |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 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
|
1538 tv.v_type, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 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
|
1540 first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 *arg = c; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 vim_free(tf); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1543 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 clear_tv(&tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 vim_free(tofree); |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 return arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1557 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 /* |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1559 * Set an environment variable, part of ex_let_one(). |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1560 */ |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1561 static char_u * |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1562 ex_let_env( |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1563 char_u *arg, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1564 typval_T *tv, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1565 int flags, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1566 char_u *endchars, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1567 char_u *op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1568 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1569 char_u *arg_end = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1570 char_u *name; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1571 int len; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1572 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1573 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1574 && (flags & ASSIGN_FOR_LOOP) == 0) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1575 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1576 emsg(_(e_cannot_lock_environment_variable)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1577 return NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1578 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1579 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1580 // Find the end of the name. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1581 ++arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1582 name = arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1583 len = get_env_len(&arg); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1584 if (len == 0) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1585 semsg(_(e_invalid_argument_str), name - 1); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1586 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1587 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1588 if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1589 semsg(_(e_wrong_variable_type_for_str_equal), op); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1590 else if (endchars != NULL |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1591 && vim_strchr(endchars, *skipwhite(arg)) == NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1592 emsg(_(e_unexpected_characters_in_let)); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1593 else if (!check_secure()) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1594 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1595 char_u *tofree = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1596 int c1 = name[len]; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1597 char_u *p; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1598 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1599 name[len] = NUL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1600 p = tv_get_string_chk(tv); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1601 if (p != NULL && op != NULL && *op == '.') |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1602 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1603 int mustfree = FALSE; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1604 char_u *s = vim_getenv(name, &mustfree); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1605 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1606 if (s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1607 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1608 p = tofree = concat_str(s, p); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1609 if (mustfree) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1610 vim_free(s); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1611 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1612 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1613 if (p != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1614 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1615 vim_setenv_ext(name, p); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1616 arg_end = arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1617 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1618 name[len] = c1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1619 vim_free(tofree); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1620 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1621 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1622 return arg_end; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1623 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1624 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1625 /* |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1626 * Set an option, part of ex_let_one(). |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1627 */ |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1628 static char_u * |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1629 ex_let_option( |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1630 char_u *arg, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1631 typval_T *tv, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1632 int flags, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1633 char_u *endchars, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1634 char_u *op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1635 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1636 char_u *p; |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1637 int scope; |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1638 char_u *arg_end = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1639 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1640 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1641 && (flags & ASSIGN_FOR_LOOP) == 0) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1642 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1643 emsg(_(e_cannot_lock_option)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1644 return NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1645 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1646 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1647 // Find the end of the name. |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1648 p = find_option_end(&arg, &scope); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1649 if (p == NULL || (endchars != NULL |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1650 && vim_strchr(endchars, *skipwhite(p)) == NULL)) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1651 emsg(_(e_unexpected_characters_in_let)); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1652 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1653 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1654 int c1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1655 long n = 0; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1656 getoption_T opt_type; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1657 long numval; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1658 char_u *stringval = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1659 char_u *s = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1660 int failed = FALSE; |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1661 int opt_p_flags; |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1662 char_u *tofree = NULL; |
26450
aea4d5e1e9d5
patch 8.2.3755: Coverity warns for using a buffer in another scope
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1663 char_u numbuf[NUMBUFLEN]; |
aea4d5e1e9d5
patch 8.2.3755: Coverity warns for using a buffer in another scope
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1664 |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1665 c1 = *p; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1666 *p = NUL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1667 |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1668 opt_type = get_option_value(arg, &numval, &stringval, &opt_p_flags, |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1669 scope); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1670 if ((opt_type == gov_bool |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1671 || opt_type == gov_number |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1672 || opt_type == gov_hidden_bool |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1673 || opt_type == gov_hidden_number) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1674 && (tv->v_type != VAR_STRING || !in_vim9script())) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1675 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1676 if (opt_type == gov_bool || opt_type == gov_hidden_bool) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1677 // bool, possibly hidden |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1678 n = (long)tv_get_bool(tv); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1679 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1680 // number, possibly hidden |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1681 n = (long)tv_get_number(tv); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1682 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1683 |
26528
4d8226001391
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
1684 if ((opt_p_flags & P_FUNC) && (tv->v_type == VAR_PARTIAL |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1685 || tv->v_type == VAR_FUNC)) |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1686 { |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1687 // If the option can be set to a function reference or a lambda |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1688 // and the passed value is a function reference, then convert it to |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1689 // the name (string) of the function reference. |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1690 s = tv2string(tv, &tofree, numbuf, 0); |
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1691 } |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1692 // Avoid setting a string option to the text "v:false" or similar. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1693 // In Vim9 script also don't convert a number to string. |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1694 else if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1695 && (!in_vim9script() || tv->v_type != VAR_NUMBER)) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1696 s = tv_get_string_chk(tv); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1697 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1698 if (op != NULL && *op != '=') |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1699 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1700 if (((opt_type == gov_bool || opt_type == gov_number) && *op == '.') |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1701 || (opt_type == gov_string && *op != '.')) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1702 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1703 semsg(_(e_wrong_variable_type_for_str_equal), op); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1704 failed = TRUE; // don't set the value |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1705 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1706 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1707 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1708 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1709 // number, in legacy script also bool |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1710 if (opt_type == gov_number |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1711 || (opt_type == gov_bool && !in_vim9script())) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1712 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1713 switch (*op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1714 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1715 case '+': n = numval + n; break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1716 case '-': n = numval - n; break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1717 case '*': n = numval * n; break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1718 case '/': n = (long)num_divide(numval, n, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1719 &failed); break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1720 case '%': n = (long)num_modulus(numval, n, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1721 &failed); break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1722 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1723 s = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1724 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1725 else if (opt_type == gov_string |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1726 && stringval != NULL && s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1727 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1728 // string |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1729 s = concat_str(stringval, s); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1730 vim_free(stringval); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1731 stringval = s; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1732 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1733 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1734 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1735 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1736 if (!failed) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1737 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1738 if (opt_type != gov_string || s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1739 { |
27934
c8d6c2736796
patch 8.2.4492: no error if an option is given a value with ":let &opt = val"
Bram Moolenaar <Bram@vim.org>
parents:
27924
diff
changeset
|
1740 char *err = set_option_value(arg, n, s, scope); |
c8d6c2736796
patch 8.2.4492: no error if an option is given a value with ":let &opt = val"
Bram Moolenaar <Bram@vim.org>
parents:
27924
diff
changeset
|
1741 |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1742 arg_end = p; |
27934
c8d6c2736796
patch 8.2.4492: no error if an option is given a value with ":let &opt = val"
Bram Moolenaar <Bram@vim.org>
parents:
27924
diff
changeset
|
1743 if (err != NULL) |
c8d6c2736796
patch 8.2.4492: no error if an option is given a value with ":let &opt = val"
Bram Moolenaar <Bram@vim.org>
parents:
27924
diff
changeset
|
1744 emsg(_(err)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1745 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1746 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1747 emsg(_(e_string_required)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1748 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1749 *p = c1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1750 vim_free(stringval); |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
26330
diff
changeset
|
1751 vim_free(tofree); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1752 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1753 return arg_end; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1754 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1755 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1756 /* |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1757 * Set a register, part of ex_let_one(). |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1758 */ |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1759 static char_u * |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1760 ex_let_register( |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1761 char_u *arg, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1762 typval_T *tv, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1763 int flags, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1764 char_u *endchars, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1765 char_u *op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1766 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1767 char_u *arg_end = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1768 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1769 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1770 && (flags & ASSIGN_FOR_LOOP) == 0) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1771 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1772 emsg(_(e_cannot_lock_register)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1773 return NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1774 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1775 ++arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1776 if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1777 semsg(_(e_wrong_variable_type_for_str_equal), op); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1778 else if (endchars != NULL |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1779 && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1780 emsg(_(e_unexpected_characters_in_let)); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1781 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1782 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1783 char_u *ptofree = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1784 char_u *p; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1785 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1786 p = tv_get_string_chk(tv); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1787 if (p != NULL && op != NULL && *op == '.') |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1788 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1789 char_u *s = get_reg_contents(*arg == '@' |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1790 ? '"' : *arg, GREG_EXPR_SRC); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1791 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1792 if (s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1793 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1794 p = ptofree = concat_str(s, p); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1795 vim_free(s); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1796 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1797 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1798 if (p != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1799 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1800 write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1801 arg_end = arg + 1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1802 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1803 vim_free(ptofree); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1804 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1805 return arg_end; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1806 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1807 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1808 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 * 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
|
1810 * 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
|
1811 * 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
|
1812 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 static char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 ex_let_one( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 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
|
1816 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
|
1817 int copy, // copy value from "tv" |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
1818 int flags, // ASSIGN_CONST, ASSIGN_FINAL, etc. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 char_u *endchars, // valid chars after variable name or NULL |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1820 char_u *op, // "+", "-", "." or NULL |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1821 int var_idx) // variable index for "let [a, b] = list" |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 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
|
1824 |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
1825 if (in_vim9script() && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0 |
23297
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
1826 && (flags & (ASSIGN_CONST | ASSIGN_FINAL)) == 0 |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1827 && 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
|
1828 { |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1829 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
|
1830 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
|
1831 } |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1832 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 if (*arg == '$') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 { |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1835 // ":let $VAR = expr": Set environment variable. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1836 return ex_let_env(arg, tv, flags, endchars, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 else if (*arg == '&') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 { |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1840 // ":let &option = expr": Set option value. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1841 // ":let &l:option = expr": Set local option value. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1842 // ":let &g:option = expr": Set global option value. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1843 // ":for &ts in range(8)": Set option value for for loop |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1844 return ex_let_option(arg, tv, flags, endchars, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 else if (*arg == '@') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 { |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1848 // ":let @r = expr": Set register contents. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1849 return ex_let_register(arg, tv, flags, endchars, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 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
|
1852 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 lval_T lv; |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1854 char_u *p; |
28273
fff70771d4bb
patch 8.2.4662: no error for using out of range list index
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
1855 int lval_flags = (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) |
fff70771d4bb
patch 8.2.4662: no error for using out of range list index
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
1856 ? GLV_NO_DECL : 0; |
fff70771d4bb
patch 8.2.4662: no error for using out of range list index
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
1857 if (op != NULL && *op != '=') |
fff70771d4bb
patch 8.2.4662: no error for using out of range list index
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
1858 lval_flags |= GLV_ASSIGN_WITH_OP; |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1859 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1860 // ":let var = expr": Set internal variable. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1861 // ":let var: type = expr": Set internal variable with type. |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1862 // ":let {expr} = expr": Idem, name made with curly braces |
28273
fff70771d4bb
patch 8.2.4662: no error for using out of range list index
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
1863 p = get_lval(arg, tv, &lv, FALSE, FALSE, lval_flags, 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
|
1864 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
|
1865 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1866 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
|
1867 *skipwhite(lv.ll_name_end)) == NULL) |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1868 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24922
diff
changeset
|
1869 emsg(_(e_unexpected_characters_in_let)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1870 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 { |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1873 set_var_lval(&lv, p, tv, copy, flags, op, var_idx); |
24446
f388a033e568
patch 8.2.2763: Vim9: cannot use type in for loop unpack at script level
Bram Moolenaar <Bram@vim.org>
parents:
24440
diff
changeset
|
1874 arg_end = lv.ll_name_end; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 clear_lval(&lv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 else |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1880 semsg(_(e_invalid_argument_str), arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 return arg_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 * ":unlet[!] var1 ... " command. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 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
|
1890 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1891 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
|
1892 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 * ":lockvar" and ":unlockvar" commands |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 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
|
1899 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 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
|
1901 int deep = 2; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 if (eap->forceit) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 deep = -1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 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
|
1906 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 deep = getdigits(&arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1911 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
|
1912 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 * ":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
|
1916 * 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
|
1917 * 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
|
1918 */ |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1919 void |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 ex_unletlock( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 exarg_T *eap, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 char_u *argstart, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1923 int deep, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1924 int glv_flags, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1925 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
|
1926 void *cookie) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 char_u *arg = argstart; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 char_u *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 int error = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 lval_T lv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 do |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 if (*arg == '$') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1937 lv.ll_name = arg; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1938 lv.ll_tv = NULL; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1939 ++arg; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 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
|
1941 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1942 semsg(_(e_invalid_argument_str), arg - 1); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1945 if (!error && !eap->skip |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1946 && 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
|
1947 error = TRUE; |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1948 name_end = arg; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 } |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1950 else |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1951 { |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1952 // 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
|
1953 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, |
23448
8f31b990ab1e
patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
1954 glv_flags | GLV_NO_DECL, FNE_CHECK_START); |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1955 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
|
1956 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
|
1957 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
|
1958 && !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
|
1959 { |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1960 if (name_end != NULL) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1961 { |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1962 emsg_severe = TRUE; |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
1963 semsg(_(e_trailing_characters_str), name_end); |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1964 } |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1965 if (!(eap->skip || error)) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1966 clear_lval(&lv); |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1967 break; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 } |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1969 |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1970 if (!error && !eap->skip |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1971 && 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
|
1972 error = TRUE; |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1973 |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1974 if (!eap->skip) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 clear_lval(&lv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 arg = skipwhite(name_end); |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1979 } 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
|
1980 |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
1981 set_nextcmd(eap, arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 static int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 do_unlet_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 lval_T *lp, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 char_u *name_end, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1988 exarg_T *eap, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1989 int deep UNUSED, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1990 void *cookie UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1992 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
|
1993 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 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
|
1997 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 cc = *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 *name_end = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2001 // 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
|
2002 if (*lp->ll_name == '$') |
28459
52ef65c0637f
patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
2003 vim_unsetenv_ext(lp->ll_name + 1); |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2004 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
|
2005 ret = FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 *name_end = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 else if ((lp->ll_list != NULL |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
2009 && value_check_lock(lp->ll_list->lv_lock, lp->ll_name, FALSE)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 || (lp->ll_dict != NULL |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
2011 && value_check_lock(lp->ll_dict->dv_lock, lp->ll_name, FALSE))) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 else if (lp->ll_range) |
28152
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2014 list_unlet_range(lp->ll_list, lp->ll_li, lp->ll_n1, |
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2015 !lp->ll_empty2, lp->ll_n2); |
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2016 else if (lp->ll_list != NULL) |
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2017 // unlet a List item. |
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2018 listitem_remove(lp->ll_list, lp->ll_li); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 else |
28152
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2020 // unlet a Dictionary item. |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
2021 dictitem_remove(lp->ll_dict, lp->ll_di, "unlet"); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 /* |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2027 * Unlet one item or a range of items from a list. |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2028 * Return OK or FAIL. |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2029 */ |
28152
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2030 void |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2031 list_unlet_range( |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2032 list_T *l, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2033 listitem_T *li_first, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2034 long n1_arg, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2035 int has_n2, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2036 long n2) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2037 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2038 listitem_T *li = li_first; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2039 int n1 = n1_arg; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2040 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2041 // Delete a range of List items. |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2042 li = li_first; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2043 n1 = n1_arg; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2044 while (li != NULL && (!has_n2 || n2 >= n1)) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2045 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2046 listitem_T *next = li->li_next; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2047 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2048 listitem_remove(l, li); |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2049 li = next; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2050 ++n1; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2051 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2052 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2053 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 * "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
|
2055 * 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
|
2056 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 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
|
2059 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 hashtab_T *ht; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 hashitem_T *hi; |
28990
84a6794a9320
patch 8.2.5017: gcc 12.1 warns for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
28821
diff
changeset
|
2062 char_u *varname = NULL; // init to shut up gcc |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 dict_T *d; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 |
23223
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2066 // can't :unlet a script variable in Vim9 script |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2067 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
|
2068 return FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2069 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 ht = find_var_ht(name, &varname); |
23223
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2071 |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2072 // can't :unlet a script variable in Vim9 script from a function |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2073 if (ht == get_script_local_ht() |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2074 && SCRIPT_ID_VALID(current_sctx.sc_sid) |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2075 && SCRIPT_ITEM(current_sctx.sc_sid)->sn_version |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2076 == SCRIPT_VERSION_VIM9 |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2077 && check_vim9_unlet(name) == FAIL) |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2078 return FAIL; |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2079 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 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
|
2081 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 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
|
2083 if (d == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 if (ht == &globvarht) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 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
|
2087 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
|
2088 d = &vimvardict; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 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
|
2092 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
|
2093 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 if (d == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2096 internal_error("do_unlet()"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 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
|
2101 if (HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 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
|
2103 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
|
2104 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 di = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 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
|
2107 || var_check_ro(di->di_flags, name, FALSE) |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
2108 || value_check_lock(d->dv_lock, name, FALSE) |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
2109 || check_hashtab_frozen(ht, "unlet")) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 delete_var(ht, hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 if (forceit) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 return OK; |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26528
diff
changeset
|
2118 semsg(_(e_no_such_variable_str), name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2122 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 * 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
|
2124 * "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
|
2125 * "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
|
2126 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2127 static int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 do_lock_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 lval_T *lp, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 char_u *name_end, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2131 exarg_T *eap, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 int deep, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2133 void *cookie UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2135 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
|
2136 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 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
|
2141 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 cc = *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 *name_end = NUL; |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2144 if (*lp->ll_name == '$') |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2145 { |
26887
612339679616
patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2146 semsg(_(e_cannot_lock_or_unlock_variable_str), lp->ll_name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 ret = FAIL; |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2148 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2151 // 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
|
2152 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
|
2153 if (di == NULL) |
26240
640b62dbf6cb
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable
Bram Moolenaar <Bram@vim.org>
parents:
26238
diff
changeset
|
2154 { |
640b62dbf6cb
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable
Bram Moolenaar <Bram@vim.org>
parents:
26238
diff
changeset
|
2155 if (in_vim9script()) |
640b62dbf6cb
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable
Bram Moolenaar <Bram@vim.org>
parents:
26238
diff
changeset
|
2156 semsg(_(e_cannot_find_variable_to_unlock_str), |
640b62dbf6cb
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable
Bram Moolenaar <Bram@vim.org>
parents:
26238
diff
changeset
|
2157 lp->ll_name); |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2158 ret = FAIL; |
26240
640b62dbf6cb
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable
Bram Moolenaar <Bram@vim.org>
parents:
26238
diff
changeset
|
2159 } |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2160 else |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2161 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2162 if ((di->di_flags & DI_FLAGS_FIX) |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2163 && 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
|
2164 && di->di_tv.v_type != VAR_LIST) |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2165 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2166 // For historic reasons this error is not given for a list |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2167 // or dict. E.g., the b: dict could be locked/unlocked. |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2168 semsg(_(e_cannot_lock_or_unlock_variable_str), lp->ll_name); |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2169 ret = FAIL; |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2170 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2171 else |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2172 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2173 if (in_vim9script()) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2174 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2175 svar_T *sv = find_typval_in_script(&di->di_tv, |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2176 0, FALSE); |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2177 |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2178 if (sv != NULL && sv->sv_const != 0) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2179 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2180 semsg(_(e_cannot_change_readonly_variable_str), |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2181 lp->ll_name); |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2182 ret = FAIL; |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2183 } |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2184 } |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2185 |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2186 if (ret == OK) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2187 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2188 if (lock) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2189 di->di_flags |= DI_FLAGS_LOCK; |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2190 else |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2191 di->di_flags &= ~DI_FLAGS_LOCK; |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2192 if (deep != 0) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2193 item_lock(&di->di_tv, deep, lock, FALSE); |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2194 } |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2195 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2196 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2198 *name_end = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 } |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
2200 else if (deep == 0) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
2201 { |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
2202 // nothing to do |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
2203 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 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
|
2205 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 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
|
2207 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 // (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
|
2209 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
|
2210 { |
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
|
2211 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
|
2212 li = li->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 ++lp->ll_n1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 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
|
2217 // (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
|
2218 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
|
2219 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2220 // (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
|
2221 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
|
2222 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2224 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 * 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
|
2228 * 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
|
2229 * 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
|
2230 */ |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
2231 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
|
2232 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
|
2233 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 static int recurse = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 listitem_T *li; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 dict_T *d; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 blob_T *b; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2240 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2241 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 if (recurse >= DICT_MAXNEST) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 { |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2244 emsg(_(e_variable_nested_too_deep_for_unlock)); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 if (deep == 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 ++recurse; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 // 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
|
2252 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 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
|
2254 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 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
|
2256 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 switch (tv->v_type) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 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
|
2260 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
|
2261 case VAR_VOID: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 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
|
2263 case VAR_BOOL: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 case VAR_STRING: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 case VAR_FUNC: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 case VAR_PARTIAL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 case VAR_FLOAT: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 case VAR_SPECIAL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 case VAR_JOB: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 case VAR_CHANNEL: |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24490
diff
changeset
|
2271 case VAR_INSTR: |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
2272 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
2273 case VAR_OBJECT: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2274 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 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
|
2277 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
|
2278 && !(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
|
2279 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 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
|
2282 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2283 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
|
2284 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2286 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
|
2287 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
|
2288 && !(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
|
2289 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2290 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 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
|
2292 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 l->lv_lock &= ~VAR_LOCKED; |
27394
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2294 if (deep < 0 || deep > 1) |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2295 { |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2296 if (l->lv_first == &range_list_item) |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2297 l->lv_lock |= VAR_ITEMS_LOCKED; |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2298 else |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2299 { |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2300 // recursive: lock/unlock the items the List contains |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2301 CHECK_LIST_MATERIALIZE(l); |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2302 FOR_ALL_LIST_ITEMS(l, li) item_lock(&li->li_tv, |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2303 deep - 1, lock, check_refcount); |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2304 } |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2305 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2306 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 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
|
2309 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
|
2310 && !(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
|
2311 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 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
|
2314 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 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
|
2316 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
|
2317 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 // 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
|
2319 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
|
2320 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
|
2321 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 --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
|
2325 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
|
2326 check_refcount); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2330 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 --recurse; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2335 #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
|
2336 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2337 * 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
|
2338 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2339 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2340 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
|
2341 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2342 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
|
2343 int todo; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2344 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2345 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
|
2346 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
|
2347 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
|
2348 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2349 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
|
2350 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2351 --todo; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2352 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
|
2353 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
|
2354 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2355 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2356 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
|
2357 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2358 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2359 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2361 * 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
|
2362 * 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
|
2363 * 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
|
2364 */ |
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 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
|
2367 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
|
2368 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2369 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2370 * 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
|
2371 */ |
23598
a9433f834693
patch 8.2.2341: expresison command line completion incomplete after "g:"
Bram Moolenaar <Bram@vim.org>
parents:
23578
diff
changeset
|
2372 char_u * |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2373 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
|
2374 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2375 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
|
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 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
|
2378 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
|
2379 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2380 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
|
2381 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
|
2382 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
|
2383 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
|
2384 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2385 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
|
2386 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
|
2387 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2388 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
|
2389 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2390 *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
|
2391 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
|
2392 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
|
2393 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
|
2394 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2395 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2396 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2397 * 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
|
2398 * (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
|
2399 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2400 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
|
2401 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
|
2402 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2403 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
|
2404 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
|
2405 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
|
2406 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
|
2407 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
|
2408 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
|
2409 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
|
2410 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2411 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
|
2412 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2413 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
|
2414 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
|
2415 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2416 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2417 // 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
|
2418 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
|
2419 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2420 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
|
2421 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
|
2422 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2423 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2424 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
|
2425 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2426 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
|
2427 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
|
2428 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
|
2429 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2430 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2431 // b: variables |
27805
afbe86e8b24a
patch 8.2.4428: crash when switching tabpage while in the cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
2432 ht = &prevwin_curwin()->w_buffer->b_vars->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
|
2433 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
|
2434 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2435 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
|
2436 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
|
2437 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2438 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2439 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
|
2440 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2441 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
|
2442 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2443 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2444 // w: variables |
27805
afbe86e8b24a
patch 8.2.4428: crash when switching tabpage while in the cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
27738
diff
changeset
|
2445 ht = &prevwin_curwin()->w_vars->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
|
2446 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
|
2447 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2448 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
|
2449 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
|
2450 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2451 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2452 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
|
2453 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2454 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
|
2455 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2456 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2457 // 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
|
2458 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
|
2459 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
|
2460 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2461 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
|
2462 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
|
2463 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2464 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2465 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
|
2466 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2467 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
|
2468 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2469 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2470 // 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
|
2471 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
|
2472 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
|
2473 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2474 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
|
2475 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
|
2476 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
|
2477 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2478 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2479 char * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2480 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
|
2481 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2482 switch (nr) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2483 { |
23438
4c6ebf531284
patch 8.2.2262: Vim9: converting bool to string prefixes v:
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2484 case VVAL_FALSE: return in_vim9script() ? "false" : "v:false"; |
4c6ebf531284
patch 8.2.2262: Vim9: converting bool to string prefixes v:
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2485 case VVAL_TRUE: return in_vim9script() ? "true" : "v:true"; |
23497
2247a2ce3630
patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents:
23485
diff
changeset
|
2486 case VVAL_NULL: return in_vim9script() ? "null" : "v:null"; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2487 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
|
2488 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2489 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
|
2490 return "42"; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2491 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2492 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2493 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2494 * 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
|
2495 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2496 dict_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2497 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
|
2498 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2499 return &globvardict; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2500 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2501 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2502 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2503 * 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
|
2504 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2505 hashtab_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2506 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
|
2507 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2508 return &globvarht; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2509 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2510 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2511 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2512 * 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
|
2513 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2514 dict_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2515 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
|
2516 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2517 return &vimvardict; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2518 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2519 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2520 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2521 * 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
|
2522 * 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
|
2523 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2524 int |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2525 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
|
2526 { |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2527 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
|
2528 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
|
2529 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2530 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
|
2531 return -1; |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2532 *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
|
2533 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
|
2534 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
|
2535 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2536 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2537 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2538 /* |
17887
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2539 * Set type of v: variable to "type". |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2540 */ |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2541 void |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2542 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
|
2543 { |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2544 vimvars[idx].vv_tv_type = type; |
17887
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2545 } |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2546 |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2547 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2548 * 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
|
2549 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2552 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
|
2553 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2554 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
|
2555 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2556 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2557 char * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2558 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
|
2559 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2560 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
|
2561 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2562 |
17885
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 * 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
|
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 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
|
2567 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
|
2568 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2569 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
|
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 |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2572 type_T * |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2573 get_vim_var_type(int idx, garray_T *type_list) |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2574 { |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2575 if (vimvars[idx].vv_type != NULL) |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2576 return vimvars[idx].vv_type; |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2577 return typval2type_vimvar(&vimvars[idx].vv_tv, type_list); |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2578 } |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2579 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2580 /* |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2581 * 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
|
2582 * 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
|
2583 */ |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2584 int |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2585 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
|
2586 { |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2587 if (vimvars[idx].vv_tv_type != tv->v_type) |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2588 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21819
diff
changeset
|
2589 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
|
2590 clear_tv(tv); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2591 return FAIL; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2592 } |
19962
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2593 // 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
|
2594 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
|
2595 { |
25320
1e6da8364a02
patch 8.2.3197: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2596 semsg(_(e_cannot_change_readonly_variable_str), vimvars[idx].vv_name); |
19962
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2597 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
|
2598 } |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2599 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
|
2600 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
2601 semsg(_(e_cannot_set_variable_in_sandbox_str), vimvars[idx].vv_name); |
19962
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2602 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
|
2603 } |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2604 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
|
2605 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
|
2606 return OK; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2607 } |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2608 |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2609 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2610 * 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
|
2611 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2612 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
|
2613 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
|
2614 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2615 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
|
2616 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2617 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2618 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2619 * 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
|
2620 * 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
|
2621 * 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
|
2622 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2623 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
|
2624 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
|
2625 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2626 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
|
2627 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2628 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2629 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2630 * 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
|
2631 * needed. |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2632 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2633 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
|
2634 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
|
2635 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2636 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
|
2637 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2638 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2639 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2640 * 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
|
2641 * needed. |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2642 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2643 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
|
2644 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
|
2645 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2646 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
|
2647 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2648 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2649 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2650 * 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
|
2651 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2652 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2653 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
|
2654 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2655 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
|
2656 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2657 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
|
2658 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
|
2659 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2660 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2661 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
|
2662 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
|
2663 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2664 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2667 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2668 * 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
|
2669 * 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
|
2670 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2671 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2672 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
|
2673 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
|
2674 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
|
2675 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
|
2676 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2677 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
|
2678 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
|
2679 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
|
2680 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2683 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2684 * 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
|
2685 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2688 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
|
2689 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2690 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
|
2691 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
|
2692 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
|
2693 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2694 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2695 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2696 * 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
|
2697 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2698 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2699 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
|
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 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
|
2702 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
|
2703 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
|
2704 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2705 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2706 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2707 * 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
|
2708 * value. |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2709 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2710 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2711 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
|
2712 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
|
2713 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
|
2714 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
|
2715 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2716 clear_tv(&vimvars[idx].vv_di.di_tv); |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2717 vimvars[idx].vv_tv_type = VAR_STRING; |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2718 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
|
2719 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
|
2720 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
|
2721 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
|
2722 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2723 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
|
2724 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2725 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2726 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2727 * 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
|
2728 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2729 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2730 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
|
2731 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2732 clear_tv(&vimvars[idx].vv_di.di_tv); |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2733 vimvars[idx].vv_tv_type = VAR_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
|
2734 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
|
2735 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
|
2736 ++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
|
2737 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2738 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2739 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2740 * 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
|
2741 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2742 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2743 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
|
2744 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2745 clear_tv(&vimvars[idx].vv_di.di_tv); |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2746 vimvars[idx].vv_tv_type = VAR_DICT; |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2747 vimvars[idx].vv_dict = val; |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2748 if (val == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2749 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2750 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2751 ++val->dv_refcount; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2752 dict_set_items_ro(val); |
17885
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2755 /* |
18477
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2756 * 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
|
2757 */ |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2758 void |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2759 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
|
2760 { |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2761 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
|
2762 int i; |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2763 |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2764 if (l == NULL) |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2765 getout(1); |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2766 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
|
2767 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
|
2768 { |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2769 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
|
2770 getout(1); |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19201
diff
changeset
|
2771 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
|
2772 } |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2773 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
|
2774 } |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2775 |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2776 /* |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2777 * 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
|
2778 */ |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2779 void |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2780 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
|
2781 { |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2782 int regname = 0; |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2783 |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2784 // 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
|
2785 // "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
|
2786 #ifdef FEAT_CLIPBOARD |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2787 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
|
2788 #endif |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2789 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
|
2790 } |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2791 |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2792 /* |
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 * 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
|
2794 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2795 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2796 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
|
2797 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2798 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
|
2799 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2800 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
|
2801 regname = '"'; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2802 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2803 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
|
2804 // 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
|
2805 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
|
2806 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
|
2807 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2808 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2809 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2810 * 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
|
2811 * 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
|
2812 * 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
|
2813 * 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
|
2814 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2815 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
|
2816 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
|
2817 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2818 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
|
2819 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
|
2820 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2821 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
|
2822 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
|
2823 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2824 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2825 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2826 * 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
|
2827 * 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
|
2828 * 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
|
2829 * 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
|
2830 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2831 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
|
2832 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
|
2833 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2834 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
|
2835 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
|
2836 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2837 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
|
2838 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
|
2839 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2840 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2841 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2842 * 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
|
2843 * 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
|
2844 * 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
|
2845 * 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
|
2846 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2847 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
|
2848 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
|
2849 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2850 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
|
2851 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
|
2852 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
|
2853 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2854 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
|
2855 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
|
2856 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2857 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
|
2858 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
|
2859 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
|
2860 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2861 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2862 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
|
2863 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
|
2864 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
|
2865 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
|
2866 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2867 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
|
2868 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2869 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
|
2870 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
|
2871 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2872 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
|
2873 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
|
2874 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
|
2875 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
|
2876 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
|
2877 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
|
2878 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2879 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
|
2880 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
|
2881 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
|
2882 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2883 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
|
2884 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
|
2885 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
|
2886 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
|
2887 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2888 *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
|
2889 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2890 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
|
2891 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
|
2892 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2893 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
|
2894 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
|
2895 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
|
2896 : 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
|
2897 : "mac"); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2898 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
|
2899 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
|
2900 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
|
2901 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
|
2902 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
|
2903 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
|
2904 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
|
2905 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
|
2906 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
|
2907 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
|
2908 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
|
2909 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2910 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2911 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2912 * Get the value of internal variable "name". |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2913 * If "flags" has EVAL_VAR_IMPORT may return a VAR_ANY with v_number set to the |
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2914 * imported script ID. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2915 * 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
|
2916 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2917 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
|
2918 eval_variable( |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2919 char_u *name, |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2920 int len, // length of "name" or zero |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2921 scid_T sid, // script ID for imported item or zero |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2922 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
|
2923 dictitem_T **dip, // non-NULL when typval's dict item is needed |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2924 int flags) // EVAL_VAR_ flags |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2925 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2926 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2927 typval_T *tv = NULL; |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2928 int found = FALSE; |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
2929 hashtab_T *ht = NULL; |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2930 int cc = 0; |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2931 type_T *type = NULL; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2932 |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2933 if (len > 0) |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2934 { |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2935 // truncate the name, so that we can use strcmp() |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2936 cc = name[len]; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2937 name[len] = NUL; |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
2938 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2939 |
24922
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2940 // Check for local variable when debugging. |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2941 if ((tv = lookup_debug_var(name)) == NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2942 { |
24922
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2943 // Check for user-defined variables. |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2944 dictitem_T *v = find_var(name, &ht, flags & EVAL_VAR_NOAUTOLOAD); |
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2945 |
24922
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2946 if (v != NULL) |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2947 { |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2948 tv = &v->di_tv; |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2949 if (dip != NULL) |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2950 *dip = v; |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2951 } |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2952 else |
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2953 ht = NULL; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2954 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2955 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2956 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
|
2957 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2958 imported_T *import = NULL; |
20816
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20731
diff
changeset
|
2959 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
|
2960 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2961 if (sid == 0) |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
2962 import = find_imported(p, 0, TRUE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2963 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2964 // imported variable from another script |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2965 if (import != NULL || sid != 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2966 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2967 if ((flags & EVAL_VAR_IMPORT) == 0) |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2968 { |
27002
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
2969 if (SCRIPT_ID_VALID(sid)) |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2970 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2971 ht = &SCRIPT_VARS(sid); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2972 if (ht != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2973 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2974 dictitem_T *v = find_var_in_ht(ht, 0, name, |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2975 flags & EVAL_VAR_NOAUTOLOAD); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2976 |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2977 if (v != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2978 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2979 tv = &v->di_tv; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2980 if (dip != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2981 *dip = v; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2982 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2983 else |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2984 ht = NULL; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2985 } |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2986 } |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2987 else |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2988 { |
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2989 if (flags & EVAL_VAR_VERBOSE) |
27277
b73e3617c1d6
patch 8.2.4167: Vim9: error message for old style import
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
2990 semsg(_(e_expected_dot_after_name_str), name); |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2991 ret = FAIL; |
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2992 } |
22409
5736172d64a6
patch 8.2.1753: Vim9: crash when using import at script level
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
2993 } |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2994 else |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2995 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2996 if (rettv != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2997 { |
29828
6b7020f3d856
patch 9.0.0253: a symlink to an autoload script results in two entries
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
2998 // special value that is used in handle_subscript() |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2999 rettv->v_type = VAR_ANY; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3000 rettv->vval.v_number = sid != 0 ? sid : import->imp_sid; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3001 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3002 found = TRUE; |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3003 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3004 } |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26482
diff
changeset
|
3005 else if (in_vim9script() && (flags & EVAL_VAR_NO_FUNC) == 0) |
21955
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3006 { |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3007 int has_g_prefix = STRNCMP(name, "g:", 2) == 0; |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27110
diff
changeset
|
3008 ufunc_T *ufunc = find_func(name, FALSE); |
21955
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3009 |
25630
c26eb08a0df2
patch 8.2.3351: Vim9: using a function by name may delete it
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
3010 // In Vim9 script we can get a function reference by using the |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3011 // function name. For a global non-autoload function "g:" is |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3012 // required. |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3013 if (ufunc != NULL && (has_g_prefix |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3014 || !func_requires_g_prefix(ufunc))) |
21955
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3015 { |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
3016 found = TRUE; |
21955
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3017 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
|
3018 { |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3019 rettv->v_type = VAR_FUNC; |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3020 if (has_g_prefix) |
26528
4d8226001391
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
3021 // Keep the "g:", otherwise script-local may be |
4d8226001391
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
3022 // assumed. |
4d8226001391
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
3023 rettv->vval.v_string = vim_strsave(name); |
4d8226001391
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
3024 else |
4d8226001391
patch 8.2.3793: using "g:Func" as a funcref does not work in script context
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
3025 rettv->vval.v_string = vim_strsave(ufunc->uf_name); |
25630
c26eb08a0df2
patch 8.2.3351: Vim9: using a function by name may delete it
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
3026 if (rettv->vval.v_string != NULL) |
c26eb08a0df2
patch 8.2.3351: Vim9: using a function by name may delete it
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
3027 func_ref(ufunc->uf_name); |
21955
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3028 } |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3029 } |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
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 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3032 |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
3033 if (!found) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3034 { |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3035 if (tv == NULL) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3036 { |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
3037 if (rettv != NULL && (flags & EVAL_VAR_VERBOSE)) |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21819
diff
changeset
|
3038 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
|
3039 ret = FAIL; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3040 } |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3041 else if (rettv != NULL) |
22802
3e0f909ca1f2
patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
22705
diff
changeset
|
3042 { |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3043 svar_T *sv = NULL; |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3044 int was_assigned = FALSE; |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3045 |
25232
346002a63bc6
patch 8.2.3152: Vim9: accessing "s:" results in an error
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
3046 if (ht != NULL && ht == get_script_local_ht() |
346002a63bc6
patch 8.2.3152: Vim9: accessing "s:" results in an error
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
3047 && tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv) |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3048 { |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3049 sv = find_typval_in_script(tv, 0, TRUE); |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3050 if (sv != NULL) |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3051 { |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3052 type = sv->sv_type; |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3053 was_assigned = sv->sv_flags & SVFLAG_ASSIGNED; |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3054 } |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3055 } |
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3056 |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3057 // If a list or dict variable wasn't initialized and has meaningful |
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3058 // type, do it now. Not for global variables, they are not |
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3059 // declared. |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3060 if (ht != &globvarht) |
22802
3e0f909ca1f2
patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
22705
diff
changeset
|
3061 { |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3062 if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3063 && ((type != NULL && !was_assigned) |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3064 || !in_vim9script())) |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3065 { |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3066 tv->vval.v_dict = dict_alloc(); |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3067 if (tv->vval.v_dict != NULL) |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3068 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3069 ++tv->vval.v_dict->dv_refcount; |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3070 tv->vval.v_dict->dv_type = alloc_type(type); |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3071 if (sv != NULL) |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3072 sv->sv_flags |= SVFLAG_ASSIGNED; |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3073 } |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3074 } |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3075 else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3076 && ((type != NULL && !was_assigned) |
28218
300b0ca4e46c
patch 8.2.4635: tests using null list or dict fail
Bram Moolenaar <Bram@vim.org>
parents:
28217
diff
changeset
|
3077 || !in_vim9script())) |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3078 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3079 tv->vval.v_list = list_alloc(); |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3080 if (tv->vval.v_list != NULL) |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3081 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3082 ++tv->vval.v_list->lv_refcount; |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3083 tv->vval.v_list->lv_type = alloc_type(type); |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3084 if (sv != NULL) |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3085 sv->sv_flags |= SVFLAG_ASSIGNED; |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3086 } |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3087 } |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3088 else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3089 && ((type != NULL && !was_assigned) |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3090 || !in_vim9script())) |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3091 { |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3092 tv->vval.v_blob = blob_alloc(); |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3093 if (tv->vval.v_blob != NULL) |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3094 { |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3095 ++tv->vval.v_blob->bv_refcount; |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3096 if (sv != NULL) |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3097 sv->sv_flags |= SVFLAG_ASSIGNED; |
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3098 } |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3099 } |
24482
3d5a66e478f8
patch 8.2.2781: add() silently skips when adding to null list or blob
Bram Moolenaar <Bram@vim.org>
parents:
24446
diff
changeset
|
3100 } |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3101 copy_tv(tv, rettv); |
22802
3e0f909ca1f2
patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
22705
diff
changeset
|
3102 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3103 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3104 |
31639
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
3105 if (len > 0) |
62237ea155d9
patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents:
31610
diff
changeset
|
3106 name[len] = cc; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3107 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3108 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3109 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3110 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3111 /* |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3112 * Get the value of internal variable "name", also handling "import.name". |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3113 * Return OK or FAIL. If OK is returned "rettv" must be cleared. |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3114 */ |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3115 int |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3116 eval_variable_import( |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3117 char_u *name, |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3118 typval_T *rettv) |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3119 { |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3120 char_u *s = name; |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3121 while (ASCII_ISALNUM(*s) || *s == '_') |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3122 ++s; |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3123 int len = (int)(s - name); |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3124 |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3125 if (eval_variable(name, len, 0, rettv, NULL, EVAL_VAR_IMPORT) == FAIL) |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3126 return FAIL; |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3127 if (rettv->v_type == VAR_ANY && *s == '.') |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3128 { |
31708
f6309f6742e5
patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
3129 char_u *ns = s + 1; |
f6309f6742e5
patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
3130 s = ns; |
f6309f6742e5
patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
3131 while (ASCII_ISALNUM(*s) || *s == '_') |
f6309f6742e5
patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
3132 ++s; |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3133 int sid = rettv->vval.v_number; |
31708
f6309f6742e5
patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
3134 return eval_variable(ns, (int)(s - ns), sid, rettv, NULL, 0); |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3135 } |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3136 return OK; |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3137 } |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3138 |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3139 |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31639
diff
changeset
|
3140 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3141 * 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
|
3142 * 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
|
3143 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3144 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3145 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
|
3146 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3147 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
|
3148 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
|
3149 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
|
3150 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3151 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
|
3152 return; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3153 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3154 // 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
|
3155 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
|
3156 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
|
3157 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3158 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
|
3159 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
|
3160 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3161 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
|
3162 *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
|
3163 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3164 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3165 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
|
3166 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3167 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3168 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3169 * 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
|
3170 * 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
|
3171 * Careful: "a:0" variables don't have a name. |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23509
diff
changeset
|
3172 * When "htp" is not NULL set "htp" to the hashtab_T used. |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3173 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3174 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
|
3175 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
|
3176 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3177 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
|
3178 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
|
3179 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
|
3180 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3181 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
|
3182 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
|
3183 *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
|
3184 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
|
3185 return NULL; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23509
diff
changeset
|
3186 ret = find_var_in_ht(ht, *name, varname, no_autoload); |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3187 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
|
3188 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
|
3189 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3190 // Search in parent scope for lambda |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23509
diff
changeset
|
3191 ret = find_var_in_scoped_ht(name, no_autoload); |
22942
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3192 if (ret != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3193 return ret; |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3194 |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3195 // in Vim9 script items without a scope can be script-local |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3196 if (in_vim9script() && name[0] != NUL && name[1] != ':') |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3197 { |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3198 ht = get_script_local_ht(); |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3199 if (ht != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3200 { |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23509
diff
changeset
|
3201 ret = find_var_in_ht(ht, *name, varname, no_autoload); |
22942
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3202 if (ret != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3203 { |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3204 if (htp != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3205 *htp = ht; |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3206 return ret; |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3207 } |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3208 } |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3209 } |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3210 |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3211 // When using "vim9script autoload" script-local items are prefixed but can |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3212 // be used with s:name. |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3213 if (SCRIPT_ID_VALID(current_sctx.sc_sid) |
30819
d50d32026617
patch 9.0.0744: in script in autoload dir exported variable is not found
Bram Moolenaar <Bram@vim.org>
parents:
30795
diff
changeset
|
3214 && (in_vim9script() || (name[0] == 's' && name[1] == ':'))) |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3215 { |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3216 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3217 |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3218 if (si->sn_autoload_prefix != NULL) |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3219 { |
30819
d50d32026617
patch 9.0.0744: in script in autoload dir exported variable is not found
Bram Moolenaar <Bram@vim.org>
parents:
30795
diff
changeset
|
3220 char_u *base_name = (name[0] == 's' && name[1] == ':') |
d50d32026617
patch 9.0.0744: in script in autoload dir exported variable is not found
Bram Moolenaar <Bram@vim.org>
parents:
30795
diff
changeset
|
3221 ? name + 2 : name; |
d50d32026617
patch 9.0.0744: in script in autoload dir exported variable is not found
Bram Moolenaar <Bram@vim.org>
parents:
30795
diff
changeset
|
3222 char_u *auto_name = concat_str(si->sn_autoload_prefix, base_name); |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3223 |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3224 if (auto_name != NULL) |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3225 { |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3226 ht = &globvarht; |
30819
d50d32026617
patch 9.0.0744: in script in autoload dir exported variable is not found
Bram Moolenaar <Bram@vim.org>
parents:
30795
diff
changeset
|
3227 ret = find_var_in_ht(ht, 'g', auto_name, TRUE); |
27110
62b88e6cd791
patch 8.2.4084: memory leak when looking for autoload prefixed variable
Bram Moolenaar <Bram@vim.org>
parents:
27108
diff
changeset
|
3228 vim_free(auto_name); |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3229 if (ret != NULL) |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3230 { |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3231 if (htp != NULL) |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3232 *htp = ht; |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3233 return ret; |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3234 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3235 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3236 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3237 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3238 |
22942
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3239 return NULL; |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3240 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3241 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3242 /* |
27002
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3243 * Like find_var() but if the name starts with <SNR>99_ then look in the |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3244 * referenced script (used for a funcref). |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3245 */ |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3246 dictitem_T * |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3247 find_var_also_in_script(char_u *name, hashtab_T **htp, int no_autoload) |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3248 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3249 if (STRNCMP(name, "<SNR>", 5) == 0 && isdigit(name[5])) |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3250 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3251 char_u *p = name + 5; |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3252 int sid = getdigits(&p); |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3253 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3254 if (SCRIPT_ID_VALID(sid) && *p == '_') |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3255 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3256 hashtab_T *ht = &SCRIPT_VARS(sid); |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3257 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3258 if (ht != NULL) |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3259 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3260 dictitem_T *di = find_var_in_ht(ht, 0, p + 1, no_autoload); |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3261 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3262 if (di != NULL) |
27024
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3263 { |
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3264 if (htp != NULL) |
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3265 *htp = ht; |
27002
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3266 return di; |
27024
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3267 } |
27002
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3268 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3269 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3270 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3271 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3272 return find_var(name, htp, no_autoload); |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3273 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3274 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3275 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3276 * 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
|
3277 * 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
|
3278 * 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
|
3279 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3280 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
|
3281 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
|
3282 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
|
3283 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
|
3284 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
|
3285 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
|
3286 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3287 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
|
3288 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3289 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
|
3290 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3291 // 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
|
3292 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
|
3293 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3294 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
|
3295 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
|
3296 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
|
3297 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
|
3298 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
|
3299 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
|
3300 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
|
3301 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
|
3302 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3303 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
|
3304 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3305 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3306 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
|
3307 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
|
3308 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3309 // 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
|
3310 // 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
|
3311 // 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
|
3312 // 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
|
3313 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
|
3314 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3315 // 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
|
3316 // 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
|
3317 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
|
3318 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
|
3319 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
|
3320 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3321 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
|
3322 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
|
3323 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3324 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
|
3325 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3326 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3327 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3328 * 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
|
3329 */ |
22531
2df99e237965
patch 8.2.1814: missing change to remove "static"
Bram Moolenaar <Bram@vim.org>
parents:
22480
diff
changeset
|
3330 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
|
3331 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
|
3332 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3333 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
|
3334 |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21955
diff
changeset
|
3335 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
|
3336 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
|
3337 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3338 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3339 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3340 /* |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3341 * Look for "name[len]" in script-local variables and functions. |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3342 * When "cmd" is TRUE it must look like a command, a function must be followed |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3343 * by "(" or "->". |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3344 * Return OK when found, FAIL 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
|
3345 */ |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3346 int |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3347 lookup_scriptitem( |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3348 char_u *name, |
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3349 size_t len, |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3350 int cmd, |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3351 cctx_T *dummy UNUSED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3352 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3353 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
|
3354 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
|
3355 char_u *p; |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3356 int res; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3357 hashitem_T *hi; |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3358 int is_global = FALSE; |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3359 char_u *fname = name; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3360 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3361 if (ht == NULL) |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3362 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3363 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
|
3364 { |
20326
74002d42dda0
patch 8.2.0718: gcc warning for returning pointer to local variable
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
3365 // 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
|
3366 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
|
3367 p = buffer; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3368 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3369 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3370 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
3371 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
|
3372 if (p == NULL) |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3373 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3374 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3375 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3376 hi = hash_find(ht, p); |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3377 res = HASHITEM_EMPTY(hi) ? FAIL : OK; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3378 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3379 // if not script-local, then perhaps imported |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
3380 if (res == FAIL && find_imported(p, 0, FALSE) != NULL) |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3381 res = OK; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3382 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
|
3383 vim_free(p); |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3384 |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3385 // Find a function, so that a following "->" works. |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3386 // When used as a command require "(" or "->" to follow, "Cmd" is a user |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3387 // command while "Cmd()" is a function call. |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3388 if (res != OK) |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3389 { |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3390 p = skipwhite(name + len); |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3391 |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3392 if (!cmd || name[len] == '(' || (p[0] == '-' && p[1] == '>')) |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3393 { |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3394 // Do not check for an internal function, since it might also be a |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3395 // valid command, such as ":split" versus "split()". |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3396 // Skip "g:" before a function name. |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3397 if (name[0] == 'g' && name[1] == ':') |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3398 { |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3399 is_global = TRUE; |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3400 fname = name + 2; |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3401 } |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27110
diff
changeset
|
3402 if (find_func(fname, is_global) != NULL) |
24124
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3403 res = OK; |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3404 } |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3405 } |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3406 |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3407 return res; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3408 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3409 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3410 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3411 * 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
|
3412 * 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
|
3413 * 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
|
3414 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3415 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
|
3416 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
|
3417 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3418 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
|
3419 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
|
3420 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3421 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
|
3422 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
|
3423 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
|
3424 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3425 // 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
|
3426 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
|
3427 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
|
3428 *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
|
3429 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3430 // "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
|
3431 // Same for a few other variables marked with VV_COMPAT. |
25622
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25613
diff
changeset
|
3432 if (in_old_script(3)) |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3433 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3434 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
|
3435 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
|
3436 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
|
3437 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3438 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3439 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
|
3440 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
|
3441 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
|
3442 |
24874
14b0b35d8488
patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents:
24862
diff
changeset
|
3443 // In Vim9 script items at the script level are script-local, except |
14b0b35d8488
patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents:
24862
diff
changeset
|
3444 // for autoload names. |
14b0b35d8488
patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents:
24862
diff
changeset
|
3445 if (in_vim9script() && vim_strchr(name, AUTOLOAD_CHAR) == NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3446 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3447 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
|
3448 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
|
3449 return ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3450 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3451 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3452 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
|
3453 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3454 *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
|
3455 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
|
3456 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
|
3457 // 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
|
3458 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
|
3459 || 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
|
3460 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
|
3461 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
|
3462 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
|
3463 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
|
3464 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
|
3465 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
|
3466 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
|
3467 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
|
3468 return &vimvarht; |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19524
diff
changeset
|
3469 if (get_current_funccal() != NULL |
30124
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3470 && get_current_funccal()->fc_func->uf_def_status |
9874afdacb5f
patch 9.0.0398: members of funccall_T are inconsistently named
Bram Moolenaar <Bram@vim.org>
parents:
30053
diff
changeset
|
3471 == 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
|
3472 { |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19524
diff
changeset
|
3473 // 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
|
3474 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
|
3475 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
|
3476 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
|
3477 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
|
3478 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3479 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
|
3480 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3481 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
|
3482 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
|
3483 return ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3484 } |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3485 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
|
3486 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3487 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3488 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3489 * 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
|
3490 * 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
|
3491 * 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
|
3492 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3493 char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3494 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
|
3495 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3496 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3497 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3498 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
|
3499 if (v == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3500 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3501 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
|
3502 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3503 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3504 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3505 * 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
|
3506 * 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
|
3507 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3508 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3509 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
|
3510 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3511 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
|
3512 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3513 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
|
3514 if (sv == NULL) |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3515 return; |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3516 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
|
3517 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
|
3518 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3519 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3520 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3521 * 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
|
3522 * 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
|
3523 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3524 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3525 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
|
3526 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3527 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
|
3528 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
|
3529 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
|
3530 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
|
3531 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
|
3532 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
|
3533 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
|
3534 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
|
3535 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
|
3536 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
|
3537 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3538 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3539 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3540 * 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
|
3541 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3542 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3543 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
|
3544 { |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3545 // 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
|
3546 // 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
|
3547 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
|
3548 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
|
3549 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3550 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3551 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3552 * 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
|
3553 * 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
|
3554 * 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
|
3555 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3556 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3557 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
|
3558 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3559 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
|
3560 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3561 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3562 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3563 * 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
|
3564 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3565 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3566 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
|
3567 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3568 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3569 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3570 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3571 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3572 hash_lock(ht); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3573 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
|
3574 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
|
3575 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3576 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3577 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3578 --todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3579 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3580 // 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
|
3581 // 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
|
3582 // later. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3583 v = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3584 if (free_val) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3585 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
|
3586 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
|
3587 vim_free(v); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3588 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3589 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3590 hash_clear(ht); |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22551
diff
changeset
|
3591 hash_init(ht); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3592 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3595 * 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
|
3596 * 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
|
3597 */ |
22551
86a115a80262
patch 8.2.1824: Vim9: variables at the script level escape their scope
Bram Moolenaar <Bram@vim.org>
parents:
22531
diff
changeset
|
3598 void |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3599 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
|
3600 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3601 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
|
3602 |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3603 if (hash_remove(ht, hi, "delete variable") != OK) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3604 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3605 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3606 clear_tv(&di->di_tv); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3607 vim_free(di); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3608 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3609 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3610 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3611 * 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
|
3612 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3613 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3614 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
|
3615 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3616 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3617 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3618 char_u numbuf[NUMBUFLEN]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3619 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3620 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
|
3621 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
|
3622 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
|
3623 vim_free(tofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3624 } |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3627 list_one_var_a( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3628 char *prefix, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3629 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3630 int type, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3631 char_u *string, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3632 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
|
3633 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3634 // 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
|
3635 msg_start(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3636 msg_puts(prefix); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3637 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
|
3638 msg_puts((char *)name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3639 msg_putchar(' '); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3640 msg_advance(22); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3641 if (type == VAR_NUMBER) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3642 msg_putchar('#'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3643 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
|
3644 msg_putchar('*'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3645 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
|
3646 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3647 msg_putchar('['); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3648 if (*string == '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3649 ++string; |
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 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
|
3652 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3653 msg_putchar('{'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3654 if (*string == '{') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3655 ++string; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3656 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3657 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3658 msg_putchar(' '); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3659 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3660 msg_outtrans(string); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3661 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3662 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
|
3663 msg_puts("()"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3664 if (*first) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3665 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3666 msg_clr_eos(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3667 *first = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3668 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3669 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3670 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3671 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3672 * 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
|
3673 * 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
|
3674 * 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
|
3675 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3676 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3677 set_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3678 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3679 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3680 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
|
3681 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3682 set_var_const(name, 0, NULL, tv, copy, ASSIGN_DECL, 0); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3683 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3684 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3685 /* |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3686 * Set variable "name" to value in "tv_arg". |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3687 * When "sid" is non-zero "name" is in the script with this ID. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3688 * 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
|
3689 * 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
|
3690 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3691 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3692 set_var_const( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3693 char_u *name, |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3694 scid_T sid, |
26302
7351926fbe9e
patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents:
26240
diff
changeset
|
3695 type_T *type_arg, |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22027
diff
changeset
|
3696 typval_T *tv_arg, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3697 int copy, // make copy of value in "tv" |
24440
d2f9bdd938fa
patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24426
diff
changeset
|
3698 int flags_arg, // ASSIGN_CONST, ASSIGN_FINAL, etc. |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
3699 int var_idx) // index for ":let [a, b] = list" |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3700 { |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22027
diff
changeset
|
3701 typval_T *tv = tv_arg; |
26302
7351926fbe9e
patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents:
26240
diff
changeset
|
3702 type_T *type = type_arg; |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22027
diff
changeset
|
3703 typval_T bool_tv; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3704 dictitem_T *di; |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3705 typval_T *dest_tv; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3706 char_u *varname; |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3707 char_u *name_tofree = NULL; |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3708 hashtab_T *ht = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3709 int is_script_local; |
22266
23f5750146d9
patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents:
22240
diff
changeset
|
3710 int vim9script = in_vim9script(); |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24264
diff
changeset
|
3711 int var_in_vim9script; |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3712 int var_in_autoload = FALSE; |
24440
d2f9bdd938fa
patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24426
diff
changeset
|
3713 int flags = flags_arg; |
26482
b115b552071f
patch 8.2.3771: Vim9: accessing freed memory when checking type
Bram Moolenaar <Bram@vim.org>
parents:
26450
diff
changeset
|
3714 int free_tv_arg = !copy; // free tv_arg if not used |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3715 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3716 if (sid != 0) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3717 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3718 if (SCRIPT_ID_VALID(sid)) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3719 ht = &SCRIPT_VARS(sid); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3720 varname = name; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3721 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3722 else |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3723 { |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3724 scriptitem_T *si; |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3725 |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3726 if (in_vim9script() && is_export |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3727 && SCRIPT_ID_VALID(current_sctx.sc_sid) |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3728 && (si = SCRIPT_ITEM(current_sctx.sc_sid)) |
27950
aacc98a38cf3
patch 8.2.4500: Vim9: can declare a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27934
diff
changeset
|
3729 ->sn_autoload_prefix != NULL) |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3730 { |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3731 // In a vim9 autoload script an exported variable is put in the |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3732 // global namespace with the autoload prefix. |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3733 var_in_autoload = TRUE; |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3734 varname = concat_str(si->sn_autoload_prefix, name); |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3735 if (varname == NULL) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3736 goto failed; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3737 name_tofree = varname; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3738 ht = &globvarht; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3739 } |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3740 else |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3741 ht = find_var_ht(name, &varname); |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3742 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3743 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
|
3744 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
3745 semsg(_(e_illegal_variable_name_str), name); |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3746 goto failed; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3747 } |
27583
d4921b91542c
patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
3748 is_script_local = ht == get_script_local_ht() || sid != 0 |
d4921b91542c
patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
3749 || var_in_autoload; |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3750 |
22266
23f5750146d9
patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents:
22240
diff
changeset
|
3751 if (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
|
3752 && !is_script_local |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
3753 && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0 |
23297
40f1d3f0c53e
patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23295
diff
changeset
|
3754 && (flags & (ASSIGN_CONST | ASSIGN_FINAL)) == 0 |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3755 && 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
|
3756 { |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3757 vim9_declare_error(name); |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3758 goto failed; |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3759 } |
30217
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
3760 if ((flags & ASSIGN_FOR_LOOP) && is_scoped_variable(name)) |
24440
d2f9bdd938fa
patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24426
diff
changeset
|
3761 // Do not make g:var, w:var, b:var or t:var final. |
d2f9bdd938fa
patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24426
diff
changeset
|
3762 flags &= ~ASSIGN_FINAL; |
d2f9bdd938fa
patch 8.2.2760: Vim9: no error for changing a for loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24426
diff
changeset
|
3763 |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24264
diff
changeset
|
3764 var_in_vim9script = is_script_local && current_script_is_vim9(); |
24408
96e0b898d5b4
patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents:
24281
diff
changeset
|
3765 if (var_in_vim9script && name[0] == '_' && name[1] == NUL) |
96e0b898d5b4
patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents:
24281
diff
changeset
|
3766 { |
24426
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
3767 // For "[a, _] = list" the underscore is ignored. |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
3768 if ((flags & ASSIGN_UNPACK) == 0) |
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
3769 emsg(_(e_cannot_use_underscore_here)); |
24408
96e0b898d5b4
patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents:
24281
diff
changeset
|
3770 goto failed; |
96e0b898d5b4
patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents:
24281
diff
changeset
|
3771 } |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3772 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3773 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
|
3774 |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3775 if (di == NULL && var_in_vim9script) |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22027
diff
changeset
|
3776 { |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
3777 imported_T *import = find_imported(varname, 0, FALSE); |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3778 |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3779 if (import != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3780 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3781 // imported name space cannot be used |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3782 if ((flags & ASSIGN_NO_DECL) == 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3783 { |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3784 semsg(_(e_redefining_imported_item_str), name); |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3785 goto failed; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3786 } |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3787 semsg(_(e_cannot_use_str_itself_it_is_imported), name); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3788 goto failed; |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3789 } |
27690
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3790 if (!in_vim9script()) |
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3791 { |
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3792 semsg(_(e_cannot_create_vim9_script_variable_in_function_str), |
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3793 name); |
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3794 goto failed; |
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3795 } |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3796 } |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3797 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3798 // Search in parent scope which is possible to reference from lambda |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3799 if (di == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3800 di = find_var_in_scoped_ht(name, TRUE); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3801 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3802 if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3803 && var_wrong_func_name(name, di == NULL)) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3804 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3805 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3806 if (need_convert_to_bool(type, tv)) |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3807 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3808 // Destination is a bool and the value is not, but it can be |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3809 // converted. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3810 CLEAR_FIELD(bool_tv); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3811 bool_tv.v_type = VAR_BOOL; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3812 bool_tv.vval.v_number = tv2bool(tv) ? VVAL_TRUE : VVAL_FALSE; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3813 tv = &bool_tv; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3814 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3815 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3816 if (di != NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3817 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3818 // Item already exists. Allowed to replace when reloading. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3819 if ((di->di_flags & DI_FLAGS_RELOAD) == 0) |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3820 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3821 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3822 && (flags & ASSIGN_FOR_LOOP) == 0) |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3823 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3824 emsg(_(e_cannot_modify_existing_variable)); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3825 goto failed; |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3826 } |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3827 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3828 if (is_script_local && vim9script |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3829 && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0) |
24281
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3830 { |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3831 semsg(_(e_redefining_script_item_str), name); |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3832 goto failed; |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3833 } |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3834 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3835 if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3836 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3837 where_T where = WHERE_INIT; |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
3838 svar_T *sv = find_typval_in_script(&di->di_tv, sid, TRUE); |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3839 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3840 if (sv != NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3841 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3842 // check the type and adjust to bool if needed |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3843 where.wt_index = var_idx; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3844 where.wt_variable = TRUE; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3845 if (check_script_var_type(sv, tv, name, where) == FAIL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3846 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3847 if (type == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3848 type = sv->sv_type; |
28345
fabe722b24e9
patch 8.2.4698: Vim9: script variable has no flag that it was set
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
3849 sv->sv_flags |= SVFLAG_ASSIGNED; |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3850 } |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3851 } |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3852 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3853 if ((flags & ASSIGN_FOR_LOOP) == 0 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3854 && var_check_permission(di, name) == FAIL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3855 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3856 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3857 else |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3858 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3859 // can only redefine once |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3860 di->di_flags &= ~DI_FLAGS_RELOAD; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3861 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3862 // A Vim9 script-local variable is also present in sn_all_vars |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3863 // and sn_var_vals. It may set "type" from "tv". |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3864 if (var_in_vim9script || var_in_autoload) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3865 update_vim9_script_var(FALSE, di, |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3866 var_in_autoload ? name : di->di_key, flags, |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3867 tv, &type, (flags & ASSIGN_NO_MEMBER_TYPE) == 0); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3868 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3869 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3870 // existing variable, need to clear the value |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3871 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3872 // Handle setting internal di: variables separately where needed to |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3873 // prevent changing the type. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3874 if (ht == &vimvarht) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3875 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3876 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
|
3877 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3878 VIM_CLEAR(di->di_tv.vval.v_string); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3879 if (copy || tv->v_type != VAR_STRING) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3880 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3881 char_u *val = tv_get_string(tv); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3882 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3883 // Careful: when assigning to v:errmsg and |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3884 // tv_get_string() causes an error message the variable |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3885 // will already be set. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3886 if (di->di_tv.vval.v_string == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3887 di->di_tv.vval.v_string = vim_strsave(val); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3888 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3889 else |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3890 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3891 // Take over the string to avoid an extra alloc/free. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3892 di->di_tv.vval.v_string = tv->vval.v_string; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3893 tv->vval.v_string = NULL; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3894 } |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3895 goto failed; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3896 } |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3897 else if (di->di_tv.v_type == VAR_NUMBER) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3898 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3899 di->di_tv.vval.v_number = tv_get_number(tv); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3900 if (STRCMP(varname, "searchforward") == 0) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3901 set_search_direction(di->di_tv.vval.v_number |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3902 ? '/' : '?'); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3903 #ifdef FEAT_SEARCH_EXTRA |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3904 else if (STRCMP(varname, "hlsearch") == 0) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3905 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3906 no_hlsearch = !di->di_tv.vval.v_number; |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29501
diff
changeset
|
3907 redraw_all_later(UPD_SOME_VALID); |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3908 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3909 #endif |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3910 goto failed; |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3911 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3912 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
|
3913 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3914 semsg(_(e_setting_str_to_value_with_wrong_type), name); |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3915 goto failed; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3916 } |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3917 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3918 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3919 clear_tv(&di->di_tv); |
30249
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3920 |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3921 if ((flags & ASSIGN_UPDATE_BLOCK_ID) |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3922 && SCRIPT_ID_VALID(current_sctx.sc_sid)) |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3923 { |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3924 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3925 |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3926 update_script_var_block_id(name, si->sn_current_block_id); |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3927 } |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3928 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3929 else |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3930 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3931 // Item not found, check if a function already exists. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3932 if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3933 && lookup_scriptitem(name, STRLEN(name), FALSE, NULL) == OK) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3934 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3935 semsg(_(e_redefining_script_item_str), name); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3936 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3937 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3938 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3939 // add a new variable |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3940 if (var_in_vim9script && (flags & ASSIGN_NO_DECL)) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3941 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3942 semsg(_(e_unknown_variable_str), name); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3943 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3944 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3945 |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
3946 if (check_hashtab_frozen(ht, "add variable")) |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
3947 goto failed; |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
3948 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3949 // Can't add "v:" or "a:" variable. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3950 if (ht == &vimvarht || ht == get_funccal_args_ht()) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3951 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3952 semsg(_(e_illegal_variable_name_str), name); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3953 goto failed; |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
3954 } |
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
3955 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3956 // Make sure the variable name is valid. In Vim9 script an |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3957 // autoload variable must be prefixed with "g:" unless in an |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3958 // autoload script. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3959 if (!valid_varname(varname, -1, !vim9script |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3960 || STRNCMP(name, "g:", 2) == 0 || var_in_autoload)) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3961 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3962 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3963 di = alloc(sizeof(dictitem_T) + STRLEN(varname)); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3964 if (di == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3965 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3966 STRCPY(di->di_key, varname); |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
3967 if (hash_add(ht, DI2HIKEY(di), "add variable") == FAIL) |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3968 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3969 vim_free(di); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3970 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3971 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3972 di->di_flags = DI_FLAGS_ALLOC; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3973 if (flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3974 di->di_flags |= DI_FLAGS_LOCK; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3975 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3976 // A Vim9 script-local variable is also added to sn_all_vars and |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3977 // sn_var_vals. It may set "type" from "tv". |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3978 if (var_in_vim9script || var_in_autoload) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3979 update_vim9_script_var(TRUE, di, |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3980 var_in_autoload ? name : di->di_key, flags, |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3981 tv, &type, (flags & ASSIGN_NO_MEMBER_TYPE) == 0); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3982 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3983 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3984 dest_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
|
3985 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3986 copy_tv(tv, dest_tv); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3987 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3988 { |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3989 *dest_tv = *tv; |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3990 dest_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
|
3991 init_tv(tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3992 } |
26482
b115b552071f
patch 8.2.3771: Vim9: accessing freed memory when checking type
Bram Moolenaar <Bram@vim.org>
parents:
26450
diff
changeset
|
3993 free_tv_arg = FALSE; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3994 |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23450
diff
changeset
|
3995 if (vim9script && type != NULL) |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
3996 set_tv_type(dest_tv, type); |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23450
diff
changeset
|
3997 |
23299
d5919c5fd3dc
patch 8.2.2195: failing tests for :const
Bram Moolenaar <Bram@vim.org>
parents:
23297
diff
changeset
|
3998 // ":const var = value" locks the value |
d5919c5fd3dc
patch 8.2.2195: failing tests for :const
Bram Moolenaar <Bram@vim.org>
parents:
23297
diff
changeset
|
3999 // ":final var = value" locks "var" |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
4000 if (flags & ASSIGN_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
|
4001 // 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
|
4002 // 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
|
4003 // values. |
25284
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
4004 item_lock(dest_tv, DICT_MAXNEST, TRUE, TRUE); |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
4005 |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
4006 failed: |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4007 vim_free(name_tofree); |
26482
b115b552071f
patch 8.2.3771: Vim9: accessing freed memory when checking type
Bram Moolenaar <Bram@vim.org>
parents:
26450
diff
changeset
|
4008 if (free_tv_arg) |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
4009 clear_tv(tv_arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4010 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4011 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4012 /* |
23295
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4013 * Check in this order for backwards compatibility: |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4014 * - Whether the variable is read-only |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4015 * - Whether the variable value is locked |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4016 * - Whether the variable is locked |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4017 */ |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4018 int |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4019 var_check_permission(dictitem_T *di, char_u *name) |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4020 { |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4021 if (var_check_ro(di->di_flags, name, FALSE) |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4022 || value_check_lock(di->di_tv.v_lock, name, FALSE) |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4023 || var_check_lock(di->di_flags, name, FALSE)) |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4024 return FAIL; |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4025 return OK; |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4026 } |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4027 |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
4028 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4029 * 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
|
4030 * 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
|
4031 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4032 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4033 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
|
4034 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4035 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
|
4036 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4037 if (name == NULL) |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4038 emsg(_(e_cannot_change_readonly_variable)); |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4039 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4040 semsg(_(e_cannot_change_readonly_variable_str), |
25320
1e6da8364a02
patch 8.2.3197: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
4041 use_gettext ? (char_u *)_(name) : name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4042 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4043 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4044 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
|
4045 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4046 if (name == NULL) |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4047 emsg(_(e_cannot_set_variable_in_sandbox)); |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4048 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4049 semsg(_(e_cannot_set_variable_in_sandbox_str), |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4050 use_gettext ? (char_u *)_(name) : name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4051 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4052 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4053 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4054 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4055 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4056 /* |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4057 * Return TRUE if di_flags "flags" indicates variable "name" is locked. |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4058 * Also give an error message. |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4059 */ |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4060 int |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4061 var_check_lock(int flags, char_u *name, int use_gettext) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4062 { |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4063 if (flags & DI_FLAGS_LOCK) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4064 { |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4065 semsg(_(e_variable_is_locked_str), |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4066 use_gettext ? (char_u *)_(name) : name); |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4067 return TRUE; |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4068 } |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4069 return FALSE; |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4070 } |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4071 |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4072 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4073 * 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
|
4074 * 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
|
4075 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4076 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4077 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
|
4078 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4079 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
|
4080 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4081 if (name == NULL) |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4082 emsg(_(e_cannot_delete_variable)); |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4083 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4084 semsg(_(e_cannot_delete_variable_str), |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4085 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
|
4086 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4087 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4088 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4089 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4090 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4091 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4092 * 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
|
4093 * 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
|
4094 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4095 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
|
4096 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
|
4097 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
|
4098 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
|
4099 { |
24264
db5eaad456cc
patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents:
24238
diff
changeset
|
4100 // Allow for w: b: s: and t:. In Vim9 script s: is not allowed, because |
db5eaad456cc
patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents:
24238
diff
changeset
|
4101 // the name can be used without the s: prefix. |
30035
bbcdc76dcd71
patch 9.0.0355: check for uppercase char in autoload name is wrong
Bram Moolenaar <Bram@vim.org>
parents:
29828
diff
changeset
|
4102 // Allow autoload variable. |
24264
db5eaad456cc
patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents:
24238
diff
changeset
|
4103 if (!((vim_strchr((char_u *)"wbt", name[0]) != NULL |
db5eaad456cc
patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents:
24238
diff
changeset
|
4104 || (!in_vim9script() && name[0] == 's')) && name[1] == ':') |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4105 && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') |
30035
bbcdc76dcd71
patch 9.0.0355: check for uppercase char in autoload name is wrong
Bram Moolenaar <Bram@vim.org>
parents:
29828
diff
changeset
|
4106 ? name[2] : name[0]) |
bbcdc76dcd71
patch 9.0.0355: check for uppercase char in autoload name is wrong
Bram Moolenaar <Bram@vim.org>
parents:
29828
diff
changeset
|
4107 && vim_strchr(name, '#') == NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4108 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4109 semsg(_(e_funcref_variable_name_must_start_with_capital_str), name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4110 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4111 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4112 // 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
|
4113 // 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
|
4114 // below. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4115 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
|
4116 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4117 semsg(_(e_variable_name_conflicts_with_existing_function_str), |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4118 name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4119 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4120 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4121 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4122 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4123 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4124 /* |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4125 * Return TRUE if "flags" indicates variable "name" has a locked (immutable) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4126 * value. Also give an error message, using "name" or _("name") when |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4127 * "use_gettext" is TRUE. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4128 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4129 int |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22272
diff
changeset
|
4130 value_check_lock(int lock, char_u *name, int use_gettext) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4131 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4132 if (lock & VAR_LOCKED) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4133 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4134 if (name == NULL) |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4135 emsg(_(e_value_is_locked)); |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4136 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4137 semsg(_(e_value_is_locked_str), |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4138 use_gettext ? (char_u *)_(name) : name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4139 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4140 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4141 if (lock & VAR_FIXED) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4142 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4143 if (name == NULL) |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4144 emsg(_(e_cannot_change_value)); |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4145 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4146 semsg(_(e_cannot_change_value_of_str), |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4147 use_gettext ? (char_u *)_(name) : name); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4148 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4149 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4150 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4151 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4152 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4153 /* |
23233
657216220293
patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents:
23223
diff
changeset
|
4154 * Check if a variable name is valid. When "autoload" is true "#" is allowed. |
26238
14b4c778b61e
patch 8.2.3650: Vim9: for loop variable can be a list member
Bram Moolenaar <Bram@vim.org>
parents:
26195
diff
changeset
|
4155 * If "len" is -1 use all of "varname", otherwise up to "varname[len]". |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4156 * 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
|
4157 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4158 int |
26238
14b4c778b61e
patch 8.2.3650: Vim9: for loop variable can be a list member
Bram Moolenaar <Bram@vim.org>
parents:
26195
diff
changeset
|
4159 valid_varname(char_u *varname, int len, int autoload) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4160 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4161 char_u *p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4162 |
26238
14b4c778b61e
patch 8.2.3650: Vim9: for loop variable can be a list member
Bram Moolenaar <Bram@vim.org>
parents:
26195
diff
changeset
|
4163 for (p = varname; len < 0 ? *p != NUL : p < varname + len; ++p) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4164 if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) |
23233
657216220293
patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents:
23223
diff
changeset
|
4165 && !(autoload && *p == AUTOLOAD_CHAR)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4166 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4167 semsg(_(e_illegal_variable_name_str), varname); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4168 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4169 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4170 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4171 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4172 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4173 /* |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4174 * Implements the logic to retrieve local variable and option values. |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4175 * Used by "getwinvar()" "gettabvar()" "gettabwinvar()" "getbufvar()". |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4176 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4177 static void |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4178 get_var_from( |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4179 char_u *varname, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4180 typval_T *rettv, |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4181 typval_T *deftv, // Default value if not found. |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4182 int htname, // 't'ab, 'w'indow or 'b'uffer local. |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4183 tabpage_T *tp, // can be NULL |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4184 win_T *win, |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4185 buf_T *buf) // Ignored if htname is not 'b'. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4186 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4187 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4188 int done = FALSE; |
26978
aa613a3084b9
patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4189 switchwin_T switchwin; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4190 int need_switch_win; |
29448
8f1e16995118
patch 9.0.0066: switching window uneccarily when getting buffer options
Bram Moolenaar <Bram@vim.org>
parents:
29320
diff
changeset
|
4191 int do_change_curbuf = buf != NULL && htname == 'b'; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4192 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4193 ++emsg_off; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4194 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4195 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
|
4196 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
|
4197 |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4198 if (varname != NULL && tp != NULL && win != NULL |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4199 && (htname != 'b' || buf != NULL)) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4200 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4201 // 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
|
4202 // 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
|
4203 // autocommands get blocked. |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4204 // If we have a buffer reference avoid the switching, we're saving and |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4205 // restoring curbuf directly. |
29448
8f1e16995118
patch 9.0.0066: switching window uneccarily when getting buffer options
Bram Moolenaar <Bram@vim.org>
parents:
29320
diff
changeset
|
4206 need_switch_win = !(tp == curtab && win == curwin) && !do_change_curbuf; |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4207 if (!need_switch_win || switch_win(&switchwin, win, tp, TRUE) == OK) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4208 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4209 // Handle options. There are no tab-local options. |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4210 if (*varname == '&' && htname != 't') |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4211 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4212 buf_T *save_curbuf = curbuf; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4213 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4214 // Change curbuf so the option is read from the correct buffer. |
29448
8f1e16995118
patch 9.0.0066: switching window uneccarily when getting buffer options
Bram Moolenaar <Bram@vim.org>
parents:
29320
diff
changeset
|
4215 if (do_change_curbuf) |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4216 curbuf = buf; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4217 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4218 if (varname[1] == NUL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4219 { |
29448
8f1e16995118
patch 9.0.0066: switching window uneccarily when getting buffer options
Bram Moolenaar <Bram@vim.org>
parents:
29320
diff
changeset
|
4220 // get all window-local or buffer-local options in a dict |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4221 dict_T *opts = get_winbuf_options(htname == 'b'); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4222 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4223 if (opts != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4224 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4225 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
|
4226 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4227 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4228 } |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4229 else if (eval_option(&varname, rettv, TRUE) == OK) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4230 // Local option |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4231 done = TRUE; |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4232 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4233 curbuf = save_curbuf; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4234 } |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4235 else if (*varname == NUL) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4236 { |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4237 // Empty string: return a dict with all the local variables. |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4238 if (htname == 'b') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4239 v = &buf->b_bufvar; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4240 else if (htname == 'w') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4241 v = &win->w_winvar; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4242 else |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4243 v = &tp->tp_winvar; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4244 copy_tv(&v->di_tv, rettv); |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4245 done = TRUE; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4246 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4247 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4248 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4249 hashtab_T *ht; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4250 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4251 if (htname == 'b') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4252 ht = &buf->b_vars->dv_hashtab; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4253 else if (htname == 'w') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4254 ht = &win->w_vars->dv_hashtab; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4255 else |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4256 ht = &tp->tp_vars->dv_hashtab; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4257 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4258 // Look up the variable. |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4259 v = find_var_in_ht(ht, htname, varname, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4260 if (v != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4261 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4262 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
|
4263 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4264 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4265 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4266 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4267 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4268 if (need_switch_win) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4269 // restore previous notion of curwin |
26978
aa613a3084b9
patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4270 restore_win(&switchwin, TRUE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4271 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4272 |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4273 if (!done && deftv->v_type != VAR_UNKNOWN) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4274 // use the default value |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4275 copy_tv(deftv, rettv); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4276 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4277 --emsg_off; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4278 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4279 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4280 /* |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4281 * getwinvar() and gettabwinvar() |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4282 */ |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4283 static void |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4284 getwinvar( |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4285 typval_T *argvars, |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4286 typval_T *rettv, |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4287 int off) // 1 for gettabwinvar() |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4288 { |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4289 char_u *varname; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4290 tabpage_T *tp; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4291 win_T *win; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4292 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4293 if (off == 1) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4294 tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4295 else |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4296 tp = curtab; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4297 win = find_win_by_nr(&argvars[off], tp); |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4298 varname = tv_get_string_chk(&argvars[off + 1]); |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4299 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4300 get_var_from(varname, rettv, &argvars[off + 2], 'w', tp, win, NULL); |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4301 } |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4302 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4303 /* |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4304 * 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
|
4305 */ |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4306 static void |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4307 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
|
4308 { |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4309 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
|
4310 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
|
4311 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
|
4312 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
|
4313 |
23483
ce7d6b461660
patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
4314 if (varp->v_type == VAR_BOOL) |
23485
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4315 { |
29497
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4316 if (is_string_option(varname)) |
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4317 { |
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4318 emsg(_(e_string_required)); |
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4319 return; |
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4320 } |
23483
ce7d6b461660
patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
4321 numval = (long)varp->vval.v_number; |
23485
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4322 strval = (char_u *)"0"; // avoid using "false" |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4323 } |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4324 else |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4325 { |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4326 if (!in_vim9script() || varp->v_type != VAR_STRING) |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4327 numval = (long)tv_get_number_chk(varp, &error); |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4328 strval = tv_get_string_buf_chk(varp, nbuf); |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4329 } |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4330 if (!error && strval != NULL) |
28457
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28345
diff
changeset
|
4331 set_option_value_give_err(varname, numval, strval, OPT_LOCAL); |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4332 } |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4333 |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4334 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4335 * "setwinvar()" and "settabwinvar()" functions |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4336 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4337 static void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4338 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
|
4339 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4340 win_T *win; |
26978
aa613a3084b9
patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4341 switchwin_T switchwin; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4342 int need_switch_win; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4343 char_u *varname, *winvarname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4344 typval_T *varp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4345 tabpage_T *tp = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4346 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4347 if (check_secure()) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4348 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4349 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4350 if (off == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4351 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
|
4352 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4353 tp = curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4354 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
|
4355 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
|
4356 varp = &argvars[off + 2]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4357 |
31610
8707b2b5c45e
patch 9.0.1137: some conditions are always false
Bram Moolenaar <Bram@vim.org>
parents:
31602
diff
changeset
|
4358 if (win == NULL || varname == NULL) |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4359 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4360 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4361 need_switch_win = !(tp == curtab && win == curwin); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4362 if (!need_switch_win |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4363 || switch_win(&switchwin, win, tp, TRUE) == OK) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4364 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4365 if (*varname == '&') |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4366 set_option_from_tv(varname + 1, varp); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4367 else |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4368 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4369 winvarname = alloc(STRLEN(varname) + 3); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4370 if (winvarname != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4371 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4372 STRCPY(winvarname, "w:"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4373 STRCPY(winvarname + 2, varname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4374 set_var(winvarname, varp, TRUE); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4375 vim_free(winvarname); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4376 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4377 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4378 } |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4379 if (need_switch_win) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4380 restore_win(&switchwin, TRUE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4381 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4382 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4383 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4384 * 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
|
4385 * 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
|
4386 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4387 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4388 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
|
4389 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4390 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
|
4391 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
|
4392 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
|
4393 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
|
4394 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
|
4395 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
|
4396 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4397 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4398 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4399 * 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
|
4400 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4401 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4402 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
|
4403 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4404 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
|
4405 |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
4406 if (vp->vv_tv_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
|
4407 // 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
|
4408 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
|
4409 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
|
4410 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4411 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4412 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4413 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
|
4414 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
4415 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
|
4416 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4417 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4418 typval_T tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4419 int len = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4420 int n = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4421 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4422 // 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
|
4423 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
|
4424 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
|
4425 if (len > 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4426 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4427 if (tofree != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4428 name = tofree; |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
4429 n = (eval_variable(name, len, 0, &tv, NULL, |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
4430 EVAL_VAR_NOAUTOLOAD + EVAL_VAR_IMPORT) == OK); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4431 if (n) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4432 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4433 // 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
|
4434 arg = skipwhite(arg); |
26990
4b8d836db103
patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
4435 n = (handle_subscript(&arg, name, &tv, &EVALARG_EVALUATE, |
4b8d836db103
patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
4436 FALSE) == OK); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4437 if (n) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4438 clear_tv(&tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4439 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4440 } |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
4441 if (*arg != NUL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4442 n = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4443 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4444 vim_free(tofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4445 return n; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4446 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4447 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4448 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
|
4449 #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
|
4450 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
|
4451 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
|
4452 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
|
4453 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4454 int |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4455 alloc_redir_lval(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4456 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4457 redir_lval = ALLOC_CLEAR_ONE(lval_T); |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4458 if (redir_lval == NULL) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4459 return FAIL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4460 return OK; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4461 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4462 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4463 void |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4464 clear_redir_lval(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4465 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4466 VIM_CLEAR(redir_lval); |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4467 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4468 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4469 void |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4470 init_redir_ga(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4471 { |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27024
diff
changeset
|
4472 ga_init2(&redir_ga, sizeof(char), 500); |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4473 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4474 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4475 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4476 * 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
|
4477 * 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
|
4478 * 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
|
4479 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4480 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4481 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
|
4482 { |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
4483 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
|
4484 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
|
4485 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4486 // 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
|
4487 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
|
4488 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
4489 emsg(_(e_invalid_argument)); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4490 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4491 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4492 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4493 // 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
|
4494 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
|
4495 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
|
4496 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4497 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4498 if (alloc_redir_lval() == FAIL) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4499 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4500 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
|
4501 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4502 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4503 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4504 // The output is stored in growarray "redir_ga" until redirection ends. |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4505 init_redir_ga(); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4506 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4507 // 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
|
4508 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
|
4509 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
|
4510 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
|
4511 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4512 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
|
4513 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
|
4514 // Trailing characters are present after the variable name |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
4515 semsg(_(e_trailing_characters_str), 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
|
4516 else |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
4517 semsg(_(e_invalid_argument_str), name); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4518 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
|
4519 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
|
4520 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4521 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4522 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4523 // 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
|
4524 // string |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
4525 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
|
4526 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
|
4527 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
|
4528 if (append) |
22691
dda110a14be4
patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents:
22667
diff
changeset
|
4529 set_var_lval(redir_lval, redir_endp, &tv, TRUE, |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
4530 ASSIGN_NO_DECL, (char_u *)".", 0); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4531 else |
22691
dda110a14be4
patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents:
22667
diff
changeset
|
4532 set_var_lval(redir_lval, redir_endp, &tv, TRUE, |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
4533 ASSIGN_NO_DECL, (char_u *)"=", 0); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4534 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
|
4535 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
|
4536 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4537 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
|
4538 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
|
4539 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4540 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4541 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4542 return OK; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4543 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4544 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4545 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4546 * 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
|
4547 * 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
|
4548 * 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
|
4549 * 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
|
4550 * :redir => foo |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4551 * :let foo |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4552 * :redir END |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4553 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4554 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4555 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
|
4556 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4557 int len; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4558 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4559 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
|
4560 return; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4561 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4562 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
|
4563 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
|
4564 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4565 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
|
4566 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4567 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
|
4568 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4569 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
|
4570 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
|
4571 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4572 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4573 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
|
4574 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4575 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4576 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4577 * 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
|
4578 * 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
|
4579 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4580 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4581 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
|
4582 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4583 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
|
4584 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4585 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
|
4586 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4587 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
|
4588 return; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4589 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4590 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4591 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
|
4592 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4593 // 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
|
4594 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
|
4595 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4596 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
|
4597 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
|
4598 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
|
4599 // 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
|
4600 // have changed. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4601 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
|
4602 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
|
4603 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
|
4604 set_var_lval(redir_lval, redir_endp, &tv, FALSE, 0, |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
4605 (char_u *)".", 0); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4606 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
|
4607 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4608 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4609 // 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
|
4610 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
|
4611 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4612 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
|
4613 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4614 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
|
4615 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4616 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4617 /* |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4618 * Get the collected redirected text and clear redir_ga. |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4619 */ |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4620 char_u * |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4621 get_clear_redir_ga(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4622 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4623 char_u *res; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4624 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4625 ga_append(&redir_ga, NUL); // Append the trailing NUL. |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4626 res = redir_ga.ga_data; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4627 redir_ga.ga_data = NULL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4628 return res; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4629 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4630 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4631 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4632 * "gettabvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4633 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4634 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4635 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
|
4636 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4637 char_u *varname; |
26978
aa613a3084b9
patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4638 tabpage_T *tp; |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4639 win_T *win = NULL; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4640 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4641 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4642 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4643 || check_for_string_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4644 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4645 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4646 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
|
4647 tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4648 if (tp != NULL) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4649 win = tp == curtab || tp->tp_firstwin == NULL ? firstwin |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4650 : tp->tp_firstwin; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4651 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4652 get_var_from(varname, rettv, &argvars[2], 't', tp, win, NULL); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4653 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4654 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4655 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4656 * "gettabwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4657 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4658 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4659 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
|
4660 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4661 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4662 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4663 || check_for_number_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4664 || check_for_string_arg(argvars, 2) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4665 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4666 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4667 getwinvar(argvars, rettv, 1); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4668 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4669 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4670 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4671 * "getwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4672 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4673 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4674 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
|
4675 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4676 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4677 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4678 || check_for_string_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4679 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4680 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4681 getwinvar(argvars, rettv, 0); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4682 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4683 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4684 /* |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4685 * "getbufvar()" function |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4686 */ |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4687 void |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4688 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
|
4689 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4690 char_u *varname; |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4691 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
|
4692 |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4693 if (in_vim9script() |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4694 && (check_for_buffer_arg(argvars, 0) == FAIL |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4695 || check_for_string_arg(argvars, 1) == FAIL)) |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4696 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4697 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4698 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
|
4699 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
|
4700 |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4701 get_var_from(varname, rettv, &argvars[2], 'b', curtab, curwin, buf); |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4702 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4703 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4704 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4705 * "settabvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4706 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4707 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4708 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
|
4709 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4710 tabpage_T *save_curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4711 tabpage_T *tp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4712 char_u *varname, *tabvarname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4713 typval_T *varp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4714 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4715 if (check_secure()) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4716 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4717 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4718 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4719 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4720 || check_for_string_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4721 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4722 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4723 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
|
4724 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
|
4725 varp = &argvars[2]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4726 |
31610
8707b2b5c45e
patch 9.0.1137: some conditions are always false
Bram Moolenaar <Bram@vim.org>
parents:
31602
diff
changeset
|
4727 if (varname == NULL || tp == NULL) |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4728 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4729 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4730 save_curtab = curtab; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4731 goto_tabpage_tp(tp, FALSE, FALSE); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4732 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4733 tabvarname = alloc(STRLEN(varname) + 3); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4734 if (tabvarname != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4735 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4736 STRCPY(tabvarname, "t:"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4737 STRCPY(tabvarname + 2, varname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4738 set_var(tabvarname, varp, TRUE); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4739 vim_free(tabvarname); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4740 } |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4741 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4742 // Restore current tabpage |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4743 if (valid_tabpage(save_curtab)) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4744 goto_tabpage_tp(save_curtab, FALSE, FALSE); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4745 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4746 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4747 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4748 * "settabwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4749 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4750 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4751 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
|
4752 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4753 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4754 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4755 || check_for_number_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4756 || check_for_string_arg(argvars, 2) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4757 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4758 |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4759 setwinvar(argvars, 1); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4760 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4761 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4762 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4763 * "setwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4764 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4765 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4766 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
|
4767 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4768 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4769 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4770 || check_for_string_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4771 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4772 |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4773 setwinvar(argvars, 0); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4774 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4775 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4776 /* |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4777 * "setbufvar()" function |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4778 */ |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4779 void |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4780 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
|
4781 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4782 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
|
4783 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
|
4784 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
|
4785 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4786 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
|
4787 return; |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4788 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4789 if (in_vim9script() |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4790 && (check_for_buffer_arg(argvars, 0) == FAIL |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4791 || check_for_string_arg(argvars, 1) == FAIL)) |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4792 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4793 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4794 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
|
4795 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
|
4796 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
|
4797 |
31610
8707b2b5c45e
patch 9.0.1137: some conditions are always false
Bram Moolenaar <Bram@vim.org>
parents:
31602
diff
changeset
|
4798 if (buf == NULL || varname == NULL) |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4799 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4800 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4801 if (*varname == '&') |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4802 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4803 aco_save_T aco; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4804 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4805 // Set curbuf to be our buf, temporarily. |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4806 aucmd_prepbuf(&aco, buf); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4807 if (curbuf == buf) |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4808 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4809 // Only when it worked to set "curbuf". |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4810 set_option_from_tv(varname + 1, varp); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4811 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4812 // reset notion of buffer |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4813 aucmd_restbuf(&aco); |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4814 } |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4815 } |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4816 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4817 { |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4818 bufvarname = alloc(STRLEN(varname) + 3); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4819 if (bufvarname != NULL) |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4820 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4821 buf_T *save_curbuf = curbuf; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4822 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4823 curbuf = buf; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4824 STRCPY(bufvarname, "b:"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4825 STRCPY(bufvarname + 2, varname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4826 set_var(bufvarname, varp, TRUE); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4827 vim_free(bufvarname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4828 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
|
4829 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4830 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4831 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4832 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4833 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4834 * Get a callback from "arg". It can be a Funcref or a function name. |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4835 * When "arg" is zero "res.cb_name" is set to an empty string. |
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4836 * If "res.cb_name" is allocated then "res.cb_free_name" is set to TRUE. |
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4837 * "res.cb_name" is set to NULL for an invalid argument. |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4838 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4839 callback_T |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4840 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
|
4841 { |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4842 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
|
4843 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
|
4844 |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4845 CLEAR_FIELD(res); |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4846 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
|
4847 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4848 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
|
4849 ++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
|
4850 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
|
4851 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4852 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4853 { |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4854 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
|
4855 && 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
|
4856 r = FAIL; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4857 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
|
4858 { |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4859 res.cb_name = arg->vval.v_string; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4860 if (arg->v_type == VAR_STRING) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4861 { |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4862 char_u *name = get_scriptlocal_funcname(arg->vval.v_string); |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4863 if (name != NULL) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4864 { |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4865 res.cb_name = name; |
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4866 res.cb_free_name = TRUE; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4867 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4868 } |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4869 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
|
4870 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4871 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
|
4872 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
|
4873 else |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4874 r = FAIL; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4875 |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4876 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
|
4877 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4878 emsg(_(e_invalid_callback_argument)); |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4879 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
|
4880 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4881 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4882 return res; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4883 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4884 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4885 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4886 * 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
|
4887 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4888 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4889 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
|
4890 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4891 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
|
4892 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4893 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
|
4894 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
|
4895 ++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
|
4896 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4897 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4898 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4899 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
|
4900 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
|
4901 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
|
4902 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4903 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4904 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4905 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4906 * 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
|
4907 * 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
|
4908 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4909 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4910 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
|
4911 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4912 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
|
4913 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4914 // 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
|
4915 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
|
4916 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
|
4917 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4918 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4919 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4920 // 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
|
4921 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
|
4922 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
|
4923 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4924 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
|
4925 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4926 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4927 /* |
21409
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4928 * 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
|
4929 */ |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4930 void |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4931 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
|
4932 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4933 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
|
4934 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
|
4935 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4936 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
|
4937 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
|
4938 ++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
|
4939 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4940 else |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4941 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4942 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
|
4943 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
|
4944 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
|
4945 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4946 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4947 |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4948 /* |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4949 * When a callback refers to an autoload import, change the function name to |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4950 * the "path#name" form. Uses the current script context. |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4951 * Only works when the name is allocated. |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4952 */ |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4953 void |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4954 expand_autload_callback(callback_T *cb) |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4955 { |
27362
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4956 char_u *name; |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4957 char_u *p; |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4958 imported_T *import; |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4959 |
27362
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4960 if (!in_vim9script() || cb->cb_name == NULL |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4961 || (!cb->cb_free_name |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4962 && (cb->cb_partial == NULL || cb->cb_partial->pt_name == NULL))) |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4963 return; |
27362
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4964 if (cb->cb_partial != NULL) |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4965 name = cb->cb_partial->pt_name; |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4966 else |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4967 name = cb->cb_name; |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4968 p = vim_strchr(name, '.'); |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4969 if (p == NULL) |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4970 return; |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4971 |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
4972 import = find_imported(name, p - name, FALSE); |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4973 if (import == NULL || !SCRIPT_ID_VALID(import->imp_sid)) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4974 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4975 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4976 scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4977 if (si->sn_autoload_prefix == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4978 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4979 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4980 char_u *newname = concat_str(si->sn_autoload_prefix, p + 1); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4981 if (newname == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4982 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4983 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4984 if (cb->cb_partial != NULL) |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4985 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4986 if (cb->cb_name == cb->cb_partial->pt_name) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4987 cb->cb_name = newname; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4988 vim_free(cb->cb_partial->pt_name); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4989 cb->cb_partial->pt_name = newname; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4990 } |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4991 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4992 { |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4993 vim_free(cb->cb_name); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4994 cb->cb_name = newname; |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4995 } |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4996 } |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4997 |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4998 /* |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4999 * 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
|
5000 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5001 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5002 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
|
5003 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5004 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
|
5005 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5006 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
|
5007 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
|
5008 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5009 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
|
5010 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
|
5011 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
|
5012 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5013 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
|
5014 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
|
5015 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5016 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
|
5017 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
5018 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5019 #endif // FEAT_EVAL |