Mercurial > vim
annotate src/evalvars.c @ 31602:53c3df37a2b0 v9.0.1133
patch 9.0.1133: error message names do not match the items
Commit: https://github.com/vim/vim/commit/a9fa8c58fbcc5cf8850f6963c509de272f4d4bbf
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 2 18:10:04 2023 +0000
patch 9.0.1133: error message names do not match the items
Problem: Error message names do not match the items.
Solution: Add "_str" when the text contains "%s".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 02 Jan 2023 19:15:04 +0100 |
parents | f1d5ad2b978e |
children | 8707b2b5c45e |
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}, |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
142 {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
|
143 {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
|
144 {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
|
145 {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
|
146 {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
|
147 {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
|
148 {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
|
149 {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
|
150 {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
|
151 {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
|
152 {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
|
153 {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
|
154 {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
|
155 {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
|
156 {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
|
157 {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
|
158 }; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
159 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
160 // 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
|
161 #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
|
162 #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
|
163 #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
|
164 #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
|
165 #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
|
166 #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
|
167 #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
|
168 #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
|
169 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
170 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
|
171 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
|
172 #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
|
173 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
174 // 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
|
175 #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
|
176 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
189 * 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
|
190 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
191 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
192 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
|
193 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
194 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
|
195 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
|
196 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
202 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
|
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 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
|
205 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
|
206 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
207 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
|
208 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
|
209 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 else |
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_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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
218 // 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
|
219 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
|
220 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
|
221 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
|
222 // 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
|
223 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
|
224 } |
22480
5e95de50ddd2
patch 8.2.1788: Vim9: still allows :let for declarations
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
225 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
|
226 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
|
227 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
228 set_vim_var_nr(VV_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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
235 set_vim_var_nr(VV_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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
247 set_vim_var_nr(VV_TYPE_NUMBER, VAR_TYPE_NUMBER); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
248 set_vim_var_nr(VV_TYPE_STRING, VAR_TYPE_STRING); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
249 set_vim_var_nr(VV_TYPE_FUNC, VAR_TYPE_FUNC); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
250 set_vim_var_nr(VV_TYPE_LIST, VAR_TYPE_LIST); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
251 set_vim_var_nr(VV_TYPE_DICT, VAR_TYPE_DICT); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
252 set_vim_var_nr(VV_TYPE_FLOAT, VAR_TYPE_FLOAT); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
253 set_vim_var_nr(VV_TYPE_BOOL, VAR_TYPE_BOOL); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
254 set_vim_var_nr(VV_TYPE_NONE, VAR_TYPE_NONE); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
255 set_vim_var_nr(VV_TYPE_JOB, VAR_TYPE_JOB); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
256 set_vim_var_nr(VV_TYPE_CHANNEL, VAR_TYPE_CHANNEL); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
257 set_vim_var_nr(VV_TYPE_BLOB, VAR_TYPE_BLOB); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
258 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
259 set_vim_var_nr(VV_ECHOSPACE, sc_col - 1); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
260 |
26057
92c424550367
patch 8.2.3562: cannot add color names
Bram Moolenaar <Bram@vim.org>
parents:
25955
diff
changeset
|
261 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
|
262 |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
263 // 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
|
264 // 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
|
265 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
|
266 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
267 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
268 #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
|
269 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
270 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
273 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
|
274 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
275 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
|
276 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
|
277 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
278 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
|
279 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 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
|
284 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
285 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
|
286 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
|
287 } |
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 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
|
290 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
|
291 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
|
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 // 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
|
294 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
|
295 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
296 // 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
|
297 // 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
|
298 // 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
|
299 // another script. |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
300 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
|
301 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
|
302 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
303 #endif |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
304 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
305 int |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
306 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
|
307 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
308 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
|
309 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
310 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
311 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
|
312 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
|
313 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
314 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
|
315 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
316 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
317 int |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
318 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
|
319 { |
22602
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
320 int i; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
321 int idx; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
322 int abort = FALSE; |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
323 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
|
324 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
325 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
|
326 { |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
327 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
|
328 |
22602
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
329 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
|
330 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
|
331 { |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
332 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
|
333 |
24075
c5e396fb0ebe
patch 8.2.2579: Vim9: crash in garbagecollect after for loop
Bram Moolenaar <Bram@vim.org>
parents:
24051
diff
changeset
|
334 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
|
335 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
|
336 } |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
337 } |
2c77ec32deeb
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
338 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
339 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
|
340 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
341 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
342 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
343 * Set 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
|
344 * 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
|
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 void |
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_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
|
348 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
349 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
|
350 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
|
351 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
352 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
|
353 if (val == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
354 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
355 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
356 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
|
357 if (tvp == 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 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
|
361 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
|
362 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
363 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
364 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
365 eval_charconvert( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 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
|
370 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
371 int err = FALSE; |
27330
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
372 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
|
373 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
|
374 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 if (ctx != NULL) |
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
381 current_sctx = *ctx; |
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
382 |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
383 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
|
384 err = TRUE; |
27330
aeadf4315bef
patch 8.2.4193: cannot use an import in 'charconvert'
Bram Moolenaar <Bram@vim.org>
parents:
27328
diff
changeset
|
385 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
392 if (err) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
393 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
394 return OK; |
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 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
397 # 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
|
398 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
399 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
|
400 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
401 int err = FALSE; |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
402 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
|
403 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
|
404 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
405 set_vim_var_string(VV_FNAME_IN, fname, -1); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
406 set_vim_var_string(VV_CMDARG, args, -1); |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
407 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
|
408 if (ctx != NULL) |
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
409 current_sctx = *ctx; |
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
410 |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
411 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
|
412 err = TRUE; |
27328
7382135dac01
patch 8.2.4192: cannot use an import in 'printexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27315
diff
changeset
|
413 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
414 set_vim_var_string(VV_FNAME_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
|
415 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
|
416 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
|
417 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
418 if (err) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
419 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
420 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
|
421 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
422 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
423 return OK; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
424 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
425 # endif |
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 # 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
|
428 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
429 eval_diff( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
430 char_u *origfile, |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
431 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
|
432 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
|
433 { |
27305
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
434 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
|
435 sctx_T *ctx; |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
436 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
|
437 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
442 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
|
443 if (ctx != NULL) |
30d8437ad7cc
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27285
diff
changeset
|
444 current_sctx = *ctx; |
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 // 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
|
447 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
|
448 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
|
449 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
450 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
|
451 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
|
452 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
|
453 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
|
454 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
455 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
456 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
457 eval_patch( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
458 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
|
459 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
|
460 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
|
461 { |
27315
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
462 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
|
463 sctx_T *ctx; |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
464 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
|
465 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
470 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
|
471 if (ctx != NULL) |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
472 current_sctx = *ctx; |
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 // 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
|
475 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
|
476 free_tv(tv); |
a195a900a329
patch 8.2.4186: cannot use an import in 'patchexpr'
Bram Moolenaar <Bram@vim.org>
parents:
27307
diff
changeset
|
477 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
478 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
|
479 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
|
480 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
|
481 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
|
482 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
483 # endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
484 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
485 #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
|
486 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
487 * 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
|
488 * 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
|
489 * 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
|
490 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
491 list_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
492 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
|
493 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
502 // 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
|
503 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
|
504 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
|
505 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
|
506 ++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
|
507 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
|
508 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
|
509 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
|
510 |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30399
diff
changeset
|
511 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
|
512 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
|
513 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
|
514 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
|
515 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
516 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
|
517 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
|
518 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
519 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
|
520 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
521 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
522 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
|
523 --emsg_off; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
524 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
|
525 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
|
526 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
|
527 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
528 return list; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
529 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
530 |
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 * "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
|
533 * 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
|
534 * 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
|
535 * 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
|
536 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
537 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
538 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
|
539 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
540 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
|
541 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
542 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
|
543 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
|
544 return -1; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
545 *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
|
546 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
547 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
|
548 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
|
549 return -1; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
550 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
|
551 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
552 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
553 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
554 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
555 * 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
|
556 * 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
|
557 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
560 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
|
561 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
562 *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
|
563 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
|
564 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
|
565 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
|
566 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
567 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
568 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
569 * 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
|
570 * 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
|
571 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
574 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
|
575 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
576 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
|
577 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
578 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
|
579 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
|
580 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
581 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
582 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
|
583 if (HASHITEM_EMPTY(hi)) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
584 internal_error("restore_vimvar()"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
585 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
586 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
|
587 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
588 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
589 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
590 * 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
|
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 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
|
593 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
|
594 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
595 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
|
596 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
597 |
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 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
|
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 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
|
602 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
|
603 { |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21955
diff
changeset
|
604 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
|
605 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
|
606 "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
|
607 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
608 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
609 /* |
30217
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
610 * 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
|
611 * 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
|
612 */ |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
613 int |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
614 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
|
615 { |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
616 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
|
617 && name[1] == ':' |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
618 && 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
|
619 } |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
620 |
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
621 /* |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
622 * 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
|
623 * 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
|
624 * 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
|
625 * 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
|
626 */ |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
627 char_u * |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
628 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
|
629 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
630 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
|
631 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
|
632 char_u *expr_val; |
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 if (*block_start == NUL) |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
635 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
636 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
|
637 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
638 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
639 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
|
640 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
641 block_end = skipwhite(block_end); |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
642 if (*block_end != '}') |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
643 { |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
644 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
|
645 return NULL; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
646 } |
28821
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
647 if (evaluate) |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
648 { |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
649 *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
|
650 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
|
651 *block_end = '}'; |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
652 if (expr_val == NULL) |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
653 return NULL; |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
654 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
|
655 vim_free(expr_val); |
006d525419fa
patch 8.2.4934: string interpolation fails when not evaluating
Bram Moolenaar <Bram@vim.org>
parents:
28813
diff
changeset
|
656 } |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
657 |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
658 return block_end + 1; |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
659 } |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
660 |
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 * 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
|
663 * 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
|
664 * Used for a heredoc assignment. |
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
665 * 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
|
666 */ |
29320
a74398c432a4
patch 9.0.0003: functions are global while they could be local
Bram Moolenaar <Bram@vim.org>
parents:
28990
diff
changeset
|
667 static char_u * |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
668 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
|
669 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
670 garray_T ga; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
671 char_u *p; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
672 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
673 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
|
674 p = str; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
675 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
676 while (*p != NUL) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
677 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
678 char_u *lit_start; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
679 int escaped_brace = FALSE; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
680 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
681 // 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
|
682 lit_start = p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
683 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
|
684 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
685 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
686 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
|
687 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
688 // 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
|
689 // 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
|
690 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
691 escaped_brace = TRUE; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
692 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
693 else if (*p == '}') |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
694 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
695 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
|
696 ga_clear(&ga); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
697 return NULL; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
698 } |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
699 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
700 // Append the literal part. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
701 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
|
702 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
703 if (*p == NUL) |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
704 break; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
705 |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
706 if (escaped_brace) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
707 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
708 // Skip the second brace. |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
709 ++p; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
710 continue; |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
711 } |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
712 |
28813
3626ca6a20ea
patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents:
28718
diff
changeset
|
713 // 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
|
714 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
|
715 if (p == NULL) |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
716 { |
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
717 ga_clear(&ga); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
718 return NULL; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
719 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
720 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
721 ga_append(&ga, NUL); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
722 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
723 return ga.ga_data; |
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 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
726 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 * 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
|
728 * 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
|
729 * cmd << {marker} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 * {line1} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 * {line2} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 * .... |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 * {marker} |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 * 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
|
736 * 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
|
737 * 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
|
738 * |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
739 * 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
|
740 * 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
|
741 * 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
|
742 * |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
743 * 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
|
744 * "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
|
745 * 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
|
746 * 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
|
747 * |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
748 * 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
|
749 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
750 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
|
751 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
|
752 { |
28518
1a2643893aa4
patch 8.2.4783: Coverity warns for leaking memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
753 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
|
754 char_u *marker; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 char_u *p; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
757 char_u *str; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 int evalstr = FALSE; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
764 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
|
765 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
|
766 int count = 0; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 if (eap->getline == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
770 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
|
771 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 // 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
|
775 cmd = skipwhite(cmd); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
776 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
777 while (TRUE) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 { |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
779 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
|
780 && (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
|
781 { |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
782 cmd = skipwhite(cmd + 4); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
783 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
784 // 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
|
785 // 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
|
786 // 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
|
787 // 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
|
788 p = *eap->cmdlinep; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
789 while (VIM_ISWHITE(*p)) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
790 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
791 p++; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
792 marker_indent_len++; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
793 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
794 text_indent_len = -1; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
795 |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
796 continue; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 } |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
798 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
|
799 && (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
|
800 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
801 cmd = skipwhite(cmd + 4); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
802 evalstr = TRUE; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
803 continue; |
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 break; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 // 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
|
809 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
|
810 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 marker = skipwhite(cmd); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 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
|
813 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
|
814 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
815 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
|
816 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 *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
|
819 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
|
820 { |
26861
df2de1e63de0
patch 8.2.3959: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
821 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
|
822 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 { |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
827 // 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
|
828 // 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
|
829 if (script_get) |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
830 marker = dot; |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
831 else |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
832 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26723
diff
changeset
|
833 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
|
834 return NULL; |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
19962
diff
changeset
|
835 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 l = list_alloc(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 if (l == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 return NULL; |
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 for (;;) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 int mi = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 int ti = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 |
28518
1a2643893aa4
patch 8.2.4783: Coverity warns for leaking memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
847 vim_free(theline); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 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
|
849 if (theline == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
851 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
|
852 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 // 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
|
856 // marker |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 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
|
858 && 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
|
859 mi = marker_indent_len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 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
|
861 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
863 // 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
|
864 // end marker. |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
865 if (eval_failed) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
866 continue; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
867 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 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
|
869 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 // 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
|
871 p = theline; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 text_indent_len = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 while (VIM_ISWHITE(*p)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 p++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 text_indent_len++; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 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
|
879 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 // 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
|
881 if (text_indent != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 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
|
883 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
|
884 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
886 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
|
887 if (vim9compile) |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
888 { |
28718
723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28684
diff
changeset
|
889 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
|
890 { |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
891 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
|
892 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
|
893 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
|
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 count++; |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
896 } |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
897 else |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
898 { |
28633
7a39c20a42fa
patch 8.2.4840: heredoc expression evaluated even when skipping
Bram Moolenaar <Bram@vim.org>
parents:
28560
diff
changeset
|
899 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
|
900 { |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
901 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
|
902 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
|
903 { |
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
904 // 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
|
905 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
|
906 continue; |
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 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
|
909 theline = str; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
910 } |
28560
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 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
|
913 break; |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
914 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 } |
28518
1a2643893aa4
patch 8.2.4783: Coverity warns for leaking memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
916 vim_free(theline); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 vim_free(text_indent); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 |
28560
060fc3b69697
patch 8.2.4804: expression in heredoc doesn't work for compiled function
Bram Moolenaar <Bram@vim.org>
parents:
28518
diff
changeset
|
919 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
|
920 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
|
921 |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
922 if (eval_failed) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
923 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
924 // 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
|
925 list_free(l); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
926 return NULL; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28459
diff
changeset
|
927 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 return l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 /* |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
932 * Vim9 variable declaration: |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
933 * ":var name" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
934 * ":var name: type" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
935 * ":var name = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
936 * ":var name: type = expr" |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
937 * etc. |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
938 */ |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
939 void |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
940 ex_var(exarg_T *eap) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
941 { |
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
|
942 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
|
943 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
|
944 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
945 if (!in_vim9script()) |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
946 { |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
947 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
|
948 return; |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
949 } |
27968
40c6e5f849dc
patch 8.2.4509: Vim9: can declare a variable with ":va"
Bram Moolenaar <Bram@vim.org>
parents:
27966
diff
changeset
|
950 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
|
951 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
|
952 { |
aacc98a38cf3
patch 8.2.4500: Vim9: can declare a global variable on the command line
Bram Moolenaar <Bram@vim.org>
parents:
27934
diff
changeset
|
953 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
|
954 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
|
955 } |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
956 ex_let(eap); |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
957 } |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
958 |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
959 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 * ":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
|
961 * ":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
|
962 * ":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
|
963 * ":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
|
964 * ":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
|
965 * ":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
|
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 [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
|
971 * ":let var =<< ..." heredoc |
19524
4a6a412e4565
patch 8.2.0319: file missing in distribution, comments outdated
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
972 * ":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
|
973 * |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
974 * ":final var = expr" assignment command. |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
975 * ":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
|
976 * |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 * ":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
|
978 * ":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
|
979 * ":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
|
980 * ":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
|
981 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 void |
20536
8fa783f2c69c
patch 8.2.0822: Vim9: code left over from discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20530
diff
changeset
|
983 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
|
984 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 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
|
986 char_u *expr = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 typval_T rettv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 int i; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 int var_count = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 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
|
991 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
|
992 char_u *argend; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 int first = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 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
|
995 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
|
996 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
|
997 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
|
998 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
999 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
|
1000 { |
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
|
1001 // 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
|
1002 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
|
1003 return; |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1004 } |
22667
87987c783087
patch 8.2.1882: Vim9: v:disallow_let is no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
22602
diff
changeset
|
1005 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
|
1006 { |
1cefe1c013ac
patch 8.2.1756: Vim9: :let will soon be disallowed
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
1007 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
|
1008 return; |
1cefe1c013ac
patch 8.2.1756: Vim9: :let will soon be disallowed
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
1009 } |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1010 |
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
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 |
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 // 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
|
1017 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
|
1018 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
|
1019 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1020 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
|
1021 if (argend == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 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
|
1024 --argend; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 expr = skipwhite(argend); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 concat = expr[0] == '.' |
25622
15b54e0a576b
patch 8.2.3347: check for legacy script is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
25613
diff
changeset
|
1027 && ((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
|
1028 || (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
|
1029 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
|
1030 && 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
|
1031 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
|
1032 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 // ":let" without "=": list variables |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 if (*arg == '[') |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1035 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
|
1036 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
|
1037 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
|
1038 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
|
1039 { |
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 if (vim9script) |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1041 { |
24238
e5cd25f7ffcd
patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1042 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
|
1043 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
|
1044 else |
e5cd25f7ffcd
patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents:
24124
diff
changeset
|
1045 // 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
|
1046 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
|
1047 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1048 else |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1049 { |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1050 // ":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
|
1051 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
|
1052 } |
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1053 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 else if (!eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 // ":let" |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 list_glob_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 list_buf_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 list_win_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 list_tab_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 list_script_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 list_func_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 list_vim_vars(&first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
1065 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
|
1066 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 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
|
1068 { |
30795
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1069 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
|
1070 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
|
1071 |
30795
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1072 // :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
|
1073 // :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
|
1074 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
|
1075 || !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
|
1076 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
|
1077 "=<<", expr); |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1078 else |
b8cda1e1c985
patch 9.0.0732: no check for white space before and after "=<<"
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
1079 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
|
1080 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 if (l != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 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
|
1084 if (!eap->skip) |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1085 { |
25405
747ebbce2421
patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
1086 // 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
|
1087 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
|
1088 op[0] = '='; |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1089 op[1] = NUL; |
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1090 (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
|
1091 flags, op); |
18348
9ea364ccf216
patch 8.1.2168: heredoc assignment not skipped in if block
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
1092 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 { |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1098 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
|
1099 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
|
1100 |
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
|
1101 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
|
1102 i = FAIL; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1103 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
|
1104 { |
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
|
1105 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
|
1106 |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1107 op[0] = '='; |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1108 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
|
1109 if (*expr != '=') |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 { |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
1111 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
|
1112 { |
2474c6b0c5de
patch 8.2.1502: Vim9: can use += with a :let command at script level
Bram Moolenaar <Bram@vim.org>
parents:
21879
diff
changeset
|
1113 // +=, /=, 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
|
1114 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
|
1115 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
|
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 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
|
1118 { |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1119 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
|
1120 ++len; |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1121 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
|
1122 { |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1123 ++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
|
1124 ++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
|
1125 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1126 } |
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
|
1127 expr += 2; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1129 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
|
1130 ++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
|
1131 |
26330
55e658312376
patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents:
26317
diff
changeset
|
1132 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
|
1133 || !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
|
1134 { |
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 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
|
1136 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
|
1137 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
|
1138 } |
20397
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1139 |
c225be44692a
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1140 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
|
1141 ++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
|
1142 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
|
1143 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
|
1144 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
|
1145 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
|
1146 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
|
1147 --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
|
1148 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
|
1149 |
6e8a4a30d94d
patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
23693
diff
changeset
|
1150 // 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
|
1151 // 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
|
1152 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
|
1153 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 if (eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 if (i != FAIL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 clear_tv(&rettv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
1159 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
|
1160 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 (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
|
1162 flags, op); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 clear_tv(&rettv); |
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 /* |
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
|
1169 * 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
|
1170 * 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
|
1171 * 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
|
1172 * 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
|
1173 * or concatenate. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 * Returns OK or FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 ex_let_vars( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 char_u *arg_start, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 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
|
1181 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
|
1182 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
|
1183 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
|
1184 char_u *op) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 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
|
1187 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 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
|
1189 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
|
1190 listitem_T *item; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 typval_T ltv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1193 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
|
1194 { |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1195 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
|
1196 return FAIL; |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27970
diff
changeset
|
1197 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 if (*arg != '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 // ":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
|
1201 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
|
1202 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 // ":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
|
1207 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
|
1208 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1209 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
|
1210 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 i = list_len(l); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 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
|
1215 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1216 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
|
1217 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 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
|
1220 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1221 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
|
1222 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1225 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
|
1226 item = l->lv_first; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 while (*arg != ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 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
|
1230 ++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
|
1231 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
|
1232 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
|
1233 item = item->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 if (arg == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 if (*arg == ';') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 // 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
|
1241 // 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
|
1242 l = list_alloc(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 if (l == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 while (item != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 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
|
1248 item = item->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 } |
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 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
|
1252 ltv.v_lock = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 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
|
1254 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
|
1255 ++var_idx; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 |
24426
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
1257 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
|
1258 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
|
1259 clear_tv(<v); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 if (arg == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 else if (*arg != ',' && *arg != ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 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
|
1267 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 return OK; |
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 * 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
|
1276 * 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
|
1277 * 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
|
1278 * 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
|
1279 * 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
|
1280 * 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
|
1281 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 skip_var_list( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 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
|
1285 int include_type, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 int *var_count, |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1287 int *semicolon, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1288 int silent) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 char_u *p, *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 if (*arg == '[') |
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 // "[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
|
1295 p = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 for (;;) |
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 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
|
1299 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
|
1300 if (s == p) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1302 if (!silent) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1303 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
|
1304 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 ++*var_count; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 p = skipwhite(s); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 if (*p == ']') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 else if (*p == ';') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 if (*semicolon == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 { |
27738
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
1315 if (!silent) |
d754ac2f5ac5
patch 8.2.4395: some code lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
1316 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
|
1317 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 *semicolon = 1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 else if (*p != ',') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1323 if (!silent) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1324 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
|
1325 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 return p + 1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 } |
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
|
1330 |
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
|
1331 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
|
1332 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 * 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
|
1336 * 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
|
1337 * 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
|
1338 */ |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1339 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
|
1340 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
|
1341 { |
23660
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1342 char_u *end; |
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1343 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
|
1344 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 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
|
1346 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
|
1347 |
f1cb6b4dbf72
patch 9.0.0890: no test for what patch 9.0.0827 fixes
Bram Moolenaar <Bram@vim.org>
parents:
30819
diff
changeset
|
1348 // 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
|
1349 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
|
1350 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
|
1351 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1352 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
|
1353 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
|
1354 |
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1355 // "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
|
1356 // 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
|
1357 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
|
1358 --end; |
c8f26523d7d7
patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents:
23598
diff
changeset
|
1359 |
23660
f8f460738aaa
patch 8.2.2372: confusing error message for wrong :let command
Bram Moolenaar <Bram@vim.org>
parents:
23658
diff
changeset
|
1360 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
|
1361 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
1362 if (*end == ':') |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
1363 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
|
1364 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1365 return end; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 * 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
|
1370 * 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
|
1371 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 list_hashtable_vars( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 hashtab_T *ht, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 char *prefix, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 int empty, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 int *first) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 char_u buf[IOSIZE]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1384 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
|
1385 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
|
1386 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 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
|
1388 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
|
1389 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 --todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 di = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 // 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
|
1396 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
|
1397 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
|
1398 if (message_filtered(buf)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 continue; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 if (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
|
1402 || 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
|
1403 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
|
1404 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 } |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1406 |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
1407 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
|
1408 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 * List global variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 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
|
1415 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 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
|
1417 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 |
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 buffer variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 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
|
1424 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 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
|
1426 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 * List window variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 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
|
1433 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 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
|
1435 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 * List tab page variables. |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 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
|
1442 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 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
|
1444 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 * List variables in "arg". |
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 static char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 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
|
1451 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 int error = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 int len; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 char_u *name_start; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 char_u *arg_subsc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 typval_T tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 |
20111
f40231487a49
patch 8.2.0611: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20103
diff
changeset
|
1460 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
|
1461 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 if (error || eap->skip) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 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
|
1465 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
|
1466 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 emsg_severe = TRUE; |
25613
994cad298596
patch 8.2.3343: Vim9: autoload test fails
Bram Moolenaar <Bram@vim.org>
parents:
25611
diff
changeset
|
1468 if (!did_emsg) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
1469 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
|
1470 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 // 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
|
1476 name_start = name = arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 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
|
1478 if (len <= 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 // 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
|
1481 // 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
|
1482 if (len < 0 && !aborting()) |
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 emsg_severe = TRUE; |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1485 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
|
1486 break; |
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 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
1492 arg = skipwhite(arg); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 if (tofree != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 name = tofree; |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
1495 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
|
1496 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
|
1497 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 // 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
|
1501 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
|
1502 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
|
1503 &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
|
1504 error = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 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
|
1508 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 switch (*name) |
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 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
|
1512 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
|
1513 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
|
1514 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
|
1515 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
|
1516 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
|
1517 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
|
1518 default: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1519 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
|
1520 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 char_u numbuf[NUMBUFLEN]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 char_u *tf; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 int c; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 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
|
1530 c = *arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 *arg = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 list_one_var_a("", |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 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
|
1534 tv.v_type, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 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
|
1536 first); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 *arg = c; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 vim_free(tf); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 clear_tv(&tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 } |
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 vim_free(tofree); |
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 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 return arg; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 /* |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1555 * 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
|
1556 */ |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1557 static char_u * |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1558 ex_let_env( |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1559 char_u *arg, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1560 typval_T *tv, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1561 int flags, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1562 char_u *endchars, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1563 char_u *op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1564 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1565 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
|
1566 char_u *name; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1567 int len; |
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 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
|
1570 && (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
|
1571 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1572 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
|
1573 return NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1574 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1575 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1576 // 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
|
1577 ++arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1578 name = arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1579 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
|
1580 if (len == 0) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1581 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
|
1582 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1583 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1584 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
|
1585 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
|
1586 else if (endchars != NULL |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1587 && 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
|
1588 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
|
1589 else if (!check_secure()) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1590 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1591 char_u *tofree = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1592 int c1 = name[len]; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1593 char_u *p; |
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 name[len] = NUL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1596 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
|
1597 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
|
1598 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1599 int mustfree = FALSE; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1600 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
|
1601 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1602 if (s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1603 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1604 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
|
1605 if (mustfree) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1606 vim_free(s); |
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 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1609 if (p != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1610 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1611 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
|
1612 arg_end = arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1613 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1614 name[len] = c1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1615 vim_free(tofree); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1616 } |
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 return arg_end; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1619 } |
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 * 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
|
1623 */ |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1624 static char_u * |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1625 ex_let_option( |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1626 char_u *arg, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1627 typval_T *tv, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1628 int flags, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1629 char_u *endchars, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1630 char_u *op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1631 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1632 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
|
1633 int scope; |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1634 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
|
1635 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1636 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
|
1637 && (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
|
1638 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1639 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
|
1640 return NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1641 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1642 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1643 // 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
|
1644 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
|
1645 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
|
1646 && 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
|
1647 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
|
1648 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1649 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1650 int c1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1651 long n = 0; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1652 getoption_T opt_type; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1653 long numval; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1654 char_u *stringval = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1655 char_u *s = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1656 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
|
1657 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
|
1658 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
|
1659 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
|
1660 |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1661 c1 = *p; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1662 *p = NUL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1663 |
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
|
1664 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
|
1665 scope); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1666 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
|
1667 || opt_type == gov_number |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1668 || 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
|
1669 || 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
|
1670 && (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
|
1671 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1672 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
|
1673 // bool, possibly hidden |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1674 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
|
1675 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1676 // number, possibly hidden |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1677 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
|
1678 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1679 |
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
|
1680 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
|
1681 || 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
|
1682 { |
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
|
1683 // 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
|
1684 // 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
|
1685 // 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
|
1686 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
|
1687 } |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1688 // 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
|
1689 // 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
|
1690 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
|
1691 && (!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
|
1692 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
|
1693 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1694 if (op != NULL && *op != '=') |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1695 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1696 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
|
1697 || (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
|
1698 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1699 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
|
1700 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
|
1701 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1702 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1703 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1704 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1705 // 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
|
1706 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
|
1707 || (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
|
1708 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1709 switch (*op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1710 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1711 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
|
1712 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
|
1713 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
|
1714 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
|
1715 &failed); break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1716 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
|
1717 &failed); break; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1718 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1719 s = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1720 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1721 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
|
1722 && stringval != NULL && s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1723 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1724 // string |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1725 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
|
1726 vim_free(stringval); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1727 stringval = s; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1728 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1729 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1730 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1731 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1732 if (!failed) |
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 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
|
1735 { |
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
|
1736 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
|
1737 |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1738 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
|
1739 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
|
1740 emsg(_(err)); |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1741 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1742 else |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1743 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
|
1744 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1745 *p = c1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1746 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
|
1747 vim_free(tofree); |
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 return arg_end; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1750 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1751 |
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 * 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
|
1754 */ |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1755 static char_u * |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1756 ex_let_register( |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1757 char_u *arg, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1758 typval_T *tv, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1759 int flags, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1760 char_u *endchars, |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1761 char_u *op) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1762 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1763 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
|
1764 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1765 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
|
1766 && (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
|
1767 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
1768 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
|
1769 return NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1770 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1771 ++arg; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1772 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
|
1773 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
|
1774 else if (endchars != NULL |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1775 && 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
|
1776 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
|
1777 else |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1778 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1779 char_u *ptofree = NULL; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1780 char_u *p; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1781 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1782 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
|
1783 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
|
1784 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1785 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
|
1786 ? '"' : *arg, GREG_EXPR_SRC); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1787 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1788 if (s != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1789 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1790 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
|
1791 vim_free(s); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1792 } |
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 if (p != NULL) |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1795 { |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1796 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
|
1797 arg_end = arg + 1; |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1798 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1799 vim_free(ptofree); |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1800 } |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1801 return arg_end; |
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 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1804 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 * 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
|
1806 * 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
|
1807 * 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
|
1808 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 static char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 ex_let_one( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 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
|
1812 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
|
1813 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
|
1814 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
|
1815 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
|
1816 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
|
1817 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
|
1818 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 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
|
1820 |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
1821 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
|
1822 && (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
|
1823 && 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
|
1824 { |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1825 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
|
1826 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
|
1827 } |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21548
diff
changeset
|
1828 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 if (*arg == '$') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 { |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1831 // ":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
|
1832 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
|
1833 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 else if (*arg == '&') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 { |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1836 // ":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
|
1837 // ":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
|
1838 // ":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
|
1839 // ":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
|
1840 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
|
1841 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 else if (*arg == '@') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 { |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1844 // ":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
|
1845 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
|
1846 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 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
|
1848 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 lval_T lv; |
26317
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1850 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
|
1851 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
|
1852 ? 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
|
1853 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
|
1854 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
|
1855 |
f44ce6a85c34
patch 8.2.3689: ex_let_one() is too long
Bram Moolenaar <Bram@vim.org>
parents:
26302
diff
changeset
|
1856 // ":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
|
1857 // ":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
|
1858 // ":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
|
1859 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
|
1860 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
|
1861 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
1862 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
|
1863 *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
|
1864 { |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24922
diff
changeset
|
1865 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
|
1866 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 { |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23707
diff
changeset
|
1869 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
|
1870 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
|
1871 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 clear_lval(&lv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 else |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1876 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
|
1877 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 return arg_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 |
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 * ":unlet[!] var1 ... " command. |
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 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 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
|
1886 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1887 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
|
1888 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 * ":lockvar" and ":unlockvar" commands |
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 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 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
|
1895 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 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
|
1897 int deep = 2; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 if (eap->forceit) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 deep = -1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 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
|
1902 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 deep = getdigits(&arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 arg = skipwhite(arg); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1907 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
|
1908 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 * ":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
|
1912 * 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
|
1913 * 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
|
1914 */ |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1915 void |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 ex_unletlock( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 exarg_T *eap, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 char_u *argstart, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1919 int deep, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1920 int glv_flags, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1921 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
|
1922 void *cookie) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 char_u *arg = argstart; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 char_u *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 int error = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 lval_T lv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 do |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 if (*arg == '$') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1933 lv.ll_name = arg; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1934 lv.ll_tv = NULL; |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1935 ++arg; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 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
|
1937 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
1938 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
|
1939 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1941 if (!error && !eap->skip |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1942 && 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
|
1943 error = TRUE; |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1944 name_end = arg; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 } |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1946 else |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1947 { |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1948 // 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
|
1949 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
|
1950 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
|
1951 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
|
1952 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
|
1953 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
|
1954 && !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
|
1955 { |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1956 if (name_end != NULL) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1957 { |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1958 emsg_severe = TRUE; |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26881
diff
changeset
|
1959 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
|
1960 } |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1961 if (!(eap->skip || error)) |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1962 clear_lval(&lv); |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1963 break; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 } |
20103
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1965 |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1966 if (!error && !eap->skip |
fda7bed83eb6
patch 8.2.0607: gcc warns for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20093
diff
changeset
|
1967 && 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
|
1968 error = TRUE; |
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 (!eap->skip) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 clear_lval(&lv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 arg = skipwhite(name_end); |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1975 } 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
|
1976 |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25405
diff
changeset
|
1977 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
|
1978 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 static int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 do_unlet_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 lval_T *lp, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 char_u *name_end, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1984 exarg_T *eap, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1985 int deep UNUSED, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1986 void *cookie UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
1988 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
|
1989 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 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
|
1993 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 cc = *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 *name_end = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1997 // 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
|
1998 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
|
1999 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
|
2000 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
|
2001 ret = FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2002 *name_end = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 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
|
2005 && 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
|
2006 || (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
|
2007 && 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
|
2008 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 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
|
2010 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
|
2011 !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
|
2012 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
|
2013 // 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
|
2014 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
|
2015 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
|
2016 // 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
|
2017 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
|
2018 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 /* |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2023 * 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
|
2024 * 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
|
2025 */ |
28152
b96409b84eaf
patch 8.2.4600: Vim9: not enough test coverage for executing :def function
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
2026 void |
23982
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2027 list_unlet_range( |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2028 list_T *l, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2029 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
|
2030 long n1_arg, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2031 int has_n2, |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2032 long n2) |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2033 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2034 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
|
2035 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
|
2036 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2037 // 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
|
2038 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 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 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
|
2041 { |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2042 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
|
2043 |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2044 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
|
2045 li = next; |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2046 ++n1; |
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 } |
9fcd71d0db89
patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents:
23968
diff
changeset
|
2049 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 * "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
|
2051 * 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
|
2052 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 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
|
2055 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 hashtab_T *ht; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 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
|
2058 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
|
2059 dict_T *d; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 |
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
|
2062 // 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
|
2063 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
|
2064 return FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2065 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 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
|
2067 |
98548b8fbc98
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents:
23171
diff
changeset
|
2068 // 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
|
2069 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
|
2070 && 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
|
2071 && 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
|
2072 == 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
|
2073 && 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
|
2074 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
|
2075 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 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
|
2077 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 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
|
2079 if (d == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 if (ht == &globvarht) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 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
|
2083 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
|
2084 d = &vimvardict; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 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
|
2088 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
|
2089 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 if (d == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 internal_error("do_unlet()"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 } |
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 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
|
2097 if (HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 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
|
2099 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
|
2100 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 di = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 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
|
2103 || 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
|
2104 || 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
|
2105 || 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
|
2106 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 delete_var(ht, hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 return OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 } |
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 if (forceit) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 return OK; |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26528
diff
changeset
|
2114 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
|
2115 return FAIL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 * 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
|
2120 * "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
|
2121 * "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
|
2122 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 static int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 do_lock_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 lval_T *lp, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 char_u *name_end, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2127 exarg_T *eap, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 int deep, |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2129 void *cookie UNUSED) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 { |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2131 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
|
2132 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 int cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 dictitem_T *di; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 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
|
2137 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 cc = *name_end; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 *name_end = NUL; |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2140 if (*lp->ll_name == '$') |
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2141 { |
26887
612339679616
patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2142 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
|
2143 ret = FAIL; |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2144 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 { |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2147 // 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
|
2148 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
|
2149 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
|
2150 { |
640b62dbf6cb
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable
Bram Moolenaar <Bram@vim.org>
parents:
26238
diff
changeset
|
2151 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
|
2152 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
|
2153 lp->ll_name); |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2154 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
|
2155 } |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2156 else |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2157 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2158 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
|
2159 && 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
|
2160 && 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
|
2161 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2162 // 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
|
2163 // 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
|
2164 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
|
2165 ret = FAIL; |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2166 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2167 else |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2168 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2169 if (in_vim9script()) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2170 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2171 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
|
2172 0, FALSE); |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2173 |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2174 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
|
2175 { |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2176 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
|
2177 lp->ll_name); |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2178 ret = FAIL; |
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 } |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2181 |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2182 if (ret == OK) |
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 if (lock) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2185 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
|
2186 else |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2187 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
|
2188 if (deep != 0) |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2189 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
|
2190 } |
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28273
diff
changeset
|
2191 } |
20093
646c53fa5781
patch 8.2.0602: :unlet $VAR does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
2192 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2194 *name_end = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 } |
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
|
2196 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
|
2197 { |
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
|
2198 // 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
|
2199 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2200 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
|
2201 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 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
|
2203 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 // (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
|
2205 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
|
2206 { |
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
|
2207 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
|
2208 li = li->li_next; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 ++lp->ll_n1; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2210 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 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
|
2213 // (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
|
2214 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
|
2215 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 // (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
|
2217 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
|
2218 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2220 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2221 |
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 * 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
|
2224 * 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
|
2225 * 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
|
2226 */ |
22272
eb1f5f618c75
patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents:
22266
diff
changeset
|
2227 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
|
2228 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
|
2229 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2230 static int recurse = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 list_T *l; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2232 listitem_T *li; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 dict_T *d; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 blob_T *b; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 if (recurse >= DICT_MAXNEST) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 { |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
2240 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
|
2241 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 if (deep == 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2244 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 ++recurse; |
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 // 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
|
2248 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 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
|
2250 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 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
|
2252 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 switch (tv->v_type) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 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
|
2256 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
|
2257 case VAR_VOID: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 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
|
2259 case VAR_BOOL: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 case VAR_STRING: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 case VAR_FUNC: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 case VAR_PARTIAL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 case VAR_FLOAT: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 case VAR_SPECIAL: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 case VAR_JOB: |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 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
|
2267 case VAR_INSTR: |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
2268 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
31313
diff
changeset
|
2269 case VAR_OBJECT: |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 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
|
2273 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
|
2274 && !(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
|
2275 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 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
|
2278 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 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
|
2280 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 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
|
2283 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
|
2284 && !(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
|
2285 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2286 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2287 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
|
2288 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 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
|
2290 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
|
2291 { |
69a48bcd1d80
patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
27362
diff
changeset
|
2292 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
|
2293 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
|
2294 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
|
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 // 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
|
2297 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
|
2298 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
|
2299 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
|
2300 } |
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 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2302 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2303 break; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2304 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
|
2305 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
|
2306 && !(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
|
2307 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 if (lock) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 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
|
2310 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 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
|
2312 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
|
2313 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 // 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
|
2315 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
|
2316 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
|
2317 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 --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
|
2321 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
|
2322 check_refcount); |
17873
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2325 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 } |
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 --recurse; |
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 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2331 #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
|
2332 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2333 * 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
|
2334 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2335 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2336 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
|
2337 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2338 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
|
2339 int todo; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2340 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2341 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
|
2342 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
|
2343 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
|
2344 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2345 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
|
2346 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2347 --todo; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2348 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
|
2349 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
|
2350 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2351 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2352 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
|
2353 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2354 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2355 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2356 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2357 * 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
|
2358 * 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
|
2359 * 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
|
2360 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2361 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2362 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
|
2363 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
|
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 * 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
|
2367 */ |
23598
a9433f834693
patch 8.2.2341: expresison command line completion incomplete after "g:"
Bram Moolenaar <Bram@vim.org>
parents:
23578
diff
changeset
|
2368 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
|
2369 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
|
2370 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2371 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
|
2372 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2373 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
|
2374 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
|
2375 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2376 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
|
2377 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
|
2378 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
|
2379 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
|
2380 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2381 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
|
2382 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
|
2383 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2384 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
|
2385 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2386 *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
|
2387 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
|
2388 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
|
2389 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
|
2390 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2391 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2392 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2393 * 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
|
2394 * (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
|
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 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
|
2397 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
|
2398 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2399 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
|
2400 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
|
2401 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
|
2402 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
|
2403 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
|
2404 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
|
2405 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
|
2406 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2407 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
|
2408 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2409 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
|
2410 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
|
2411 } |
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 // 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
|
2414 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
|
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 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
|
2417 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
|
2418 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2419 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2420 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
|
2421 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2422 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
|
2423 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
|
2424 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
|
2425 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2426 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2427 // 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
|
2428 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
|
2429 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
|
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 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
|
2432 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
|
2433 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2434 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2435 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
|
2436 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2437 return 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
|
2438 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2439 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2440 // 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
|
2441 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
|
2442 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
|
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 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
|
2445 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
|
2446 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2447 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2448 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
|
2449 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2450 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
|
2451 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2452 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2453 // 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
|
2454 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
|
2455 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
|
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 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
|
2458 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
|
2459 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2460 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2461 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
|
2462 ++hi; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2463 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
|
2464 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2465 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2466 // 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
|
2467 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
|
2468 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
|
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 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
|
2471 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
|
2472 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
|
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 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2475 char * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2476 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
|
2477 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2478 switch (nr) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2479 { |
23438
4c6ebf531284
patch 8.2.2262: Vim9: converting bool to string prefixes v:
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2480 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
|
2481 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
|
2482 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
|
2483 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
|
2484 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2485 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
|
2486 return "42"; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2487 } |
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 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2490 * 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
|
2491 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2492 dict_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2493 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
|
2494 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2495 return &globvardict; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2496 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2497 |
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 * 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
|
2500 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2501 hashtab_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2502 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
|
2503 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2504 return &globvarht; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2505 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2506 |
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 * 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
|
2509 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2510 dict_T * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2511 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
|
2512 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2513 return &vimvardict; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2514 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
2515 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2516 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2517 * 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
|
2518 * 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
|
2519 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2520 int |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2521 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
|
2522 { |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2523 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
|
2524 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
|
2525 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2526 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
|
2527 return -1; |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
2528 *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
|
2529 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
|
2530 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
|
2531 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2532 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2533 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2534 /* |
17887
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2535 * Set type of v: variable to "type". |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2536 */ |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2537 void |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2538 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
|
2539 { |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2540 vimvars[idx].vv_tv_type = type; |
17887
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2541 } |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2542 |
39ffd167a307
patch 8.1.1940: script tests fail
Bram Moolenaar <Bram@vim.org>
parents:
17885
diff
changeset
|
2543 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2544 * 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
|
2545 * 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
|
2546 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2547 void |
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_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
|
2549 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2550 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
|
2551 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2552 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2553 char * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2554 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
|
2555 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2556 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
|
2557 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2558 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2559 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2560 * 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
|
2561 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2562 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
|
2563 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
|
2564 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2565 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
|
2566 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2567 |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2568 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
|
2569 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
|
2570 { |
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2571 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
|
2572 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
|
2573 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
|
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 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2576 /* |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2577 * 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
|
2578 * 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
|
2579 */ |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2580 int |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2581 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
|
2582 { |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
2583 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
|
2584 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21819
diff
changeset
|
2585 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
|
2586 clear_tv(tv); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2587 return FAIL; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2588 } |
19962
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2589 // 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
|
2590 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
|
2591 { |
25320
1e6da8364a02
patch 8.2.3197: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2592 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
|
2593 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
|
2594 } |
12fa79cac39b
patch 8.2.0537: Vim9: no check for sandbox when setting v:var
Bram Moolenaar <Bram@vim.org>
parents:
19960
diff
changeset
|
2595 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
|
2596 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
2597 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
|
2598 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
|
2599 } |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2600 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
|
2601 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
|
2602 return OK; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2603 } |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2604 |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
2605 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2606 * 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
|
2607 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2608 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
|
2609 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
|
2610 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2611 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
|
2612 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2613 |
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 * 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
|
2616 * 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
|
2617 * 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
|
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 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
|
2620 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
|
2621 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2622 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
|
2623 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2624 |
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 * 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
|
2627 * needed. |
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 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
|
2630 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
|
2631 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2632 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
|
2633 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2634 |
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 * 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
|
2637 * needed. |
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 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
|
2640 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
|
2641 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2642 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
|
2643 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2644 |
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 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2649 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
|
2650 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2651 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
|
2652 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2653 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
|
2654 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
|
2655 else |
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 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
|
2658 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
|
2659 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2660 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
|
2661 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2662 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2663 /* |
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 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
|
2665 * 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
|
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 void |
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_vcount( |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2669 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
|
2670 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
|
2671 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
|
2672 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2673 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
|
2674 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
|
2675 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
|
2676 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
|
2677 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2678 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2679 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2680 * 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
|
2681 * 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
|
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 void |
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_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
|
2685 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2686 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
|
2687 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
|
2688 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2691 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2692 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2695 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
|
2696 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2697 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
|
2698 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
|
2699 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2702 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2703 * 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
|
2704 * value. |
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 void |
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_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
|
2708 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
|
2709 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
|
2710 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
|
2711 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2712 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
|
2713 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
|
2714 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
|
2715 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
|
2716 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
|
2717 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
|
2718 else |
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 = 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
|
2720 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2721 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2722 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2723 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2726 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
|
2727 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2728 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
|
2729 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
|
2730 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
|
2731 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
|
2732 ++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
|
2733 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2734 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2735 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2736 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2739 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
|
2740 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2741 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
|
2742 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
|
2743 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
|
2744 if (val == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2745 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2746 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2747 ++val->dv_refcount; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
2748 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
|
2749 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2750 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2751 /* |
18477
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2752 * 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
|
2753 */ |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2754 void |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2755 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
|
2756 { |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2757 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
|
2758 int i; |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2759 |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2760 if (l == NULL) |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2761 getout(1); |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2762 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
|
2763 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
|
2764 { |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2765 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
|
2766 getout(1); |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19201
diff
changeset
|
2767 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
|
2768 } |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2769 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
|
2770 } |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2771 |
e93cab5d0f0f
patch 8.1.2233: cannot get the Vim command line arguments
Bram Moolenaar <Bram@vim.org>
parents:
18348
diff
changeset
|
2772 /* |
20721
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2773 * 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
|
2774 */ |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2775 void |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2776 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
|
2777 { |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2778 int regname = 0; |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2779 |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2780 // 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
|
2781 // "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
|
2782 #ifdef FEAT_CLIPBOARD |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2783 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
|
2784 #endif |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2785 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
|
2786 } |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2787 |
70d561931721
patch 8.2.0913: code for resetting v:register is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
2788 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2789 * 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
|
2790 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2791 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2792 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
|
2793 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2794 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
|
2795 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2796 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
|
2797 regname = '"'; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2798 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2799 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
|
2800 // 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
|
2801 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
|
2802 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
|
2803 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2804 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2805 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2806 * 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
|
2807 * 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
|
2808 * 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
|
2809 * 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
|
2810 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2811 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
|
2812 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
|
2813 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2814 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
|
2815 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
|
2816 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2817 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
|
2818 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
|
2819 } |
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 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2822 * 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
|
2823 * 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
|
2824 * 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
|
2825 * 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
|
2826 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2827 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
|
2828 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
|
2829 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2830 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
|
2831 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
|
2832 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2833 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
|
2834 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
|
2835 } |
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 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2838 * 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
|
2839 * 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
|
2840 * 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
|
2841 * 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
|
2842 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2843 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
|
2844 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
|
2845 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2846 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
|
2847 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
|
2848 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
|
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 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
|
2851 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
|
2852 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2853 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
|
2854 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
|
2855 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2858 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
|
2859 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
|
2860 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
|
2861 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
|
2862 else |
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 = 0; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2864 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2865 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
|
2866 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
|
2867 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2868 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
|
2869 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
|
2870 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
|
2871 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
|
2872 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
|
2873 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
|
2874 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2875 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
|
2876 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
|
2877 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
|
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 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
|
2880 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
|
2881 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
|
2882 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
|
2883 else |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2884 *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
|
2885 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2886 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
|
2887 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
|
2888 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2889 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
|
2890 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
|
2891 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
|
2892 : 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
|
2893 : "mac"); |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2894 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
|
2895 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
|
2896 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
|
2897 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
|
2898 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
|
2899 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
|
2900 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
|
2901 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
|
2902 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
|
2903 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
|
2904 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
|
2905 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2906 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
2907 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2908 * 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
|
2909 * 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
|
2910 * imported script ID. |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2911 * 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
|
2912 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2913 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
|
2914 eval_variable( |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2915 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2916 int len, // length of "name" |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2917 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
|
2918 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
|
2919 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
|
2920 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
|
2921 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2922 int ret = OK; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2923 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
|
2924 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
|
2925 hashtab_T *ht = NULL; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2926 int cc; |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2927 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
|
2928 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2929 // truncate the name, so that we can use strcmp() |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2930 cc = name[len]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2931 name[len] = NUL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2932 |
24922
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2933 // Check for local variable when debugging. |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2934 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
|
2935 { |
24922
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2936 // 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
|
2937 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
|
2938 |
24922
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2939 if (v != NULL) |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2940 { |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2941 tv = &v->di_tv; |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2942 if (dip != NULL) |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2943 *dip = v; |
0d8baefcf4ed
patch 8.2.2998: Vim9: disassemble test fails
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
2944 } |
25186
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2945 else |
0a3b1c66d3f2
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25184
diff
changeset
|
2946 ht = NULL; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2947 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2948 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21267
diff
changeset
|
2949 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
|
2950 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2951 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
|
2952 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
|
2953 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2954 if (sid == 0) |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
2955 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
|
2956 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2957 // 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
|
2958 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
|
2959 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2960 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
|
2961 { |
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
|
2962 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
|
2963 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2964 ht = &SCRIPT_VARS(sid); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2965 if (ht != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2966 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2967 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
|
2968 flags & EVAL_VAR_NOAUTOLOAD); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2969 |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2970 if (v != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2971 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2972 tv = &v->di_tv; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2973 if (dip != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2974 *dip = v; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2975 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2976 else |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2977 ht = NULL; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2978 } |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2979 } |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2980 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
|
2981 { |
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
2982 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
|
2983 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
|
2984 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
|
2985 } |
22409
5736172d64a6
patch 8.2.1753: Vim9: crash when using import at script level
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
2986 } |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2987 else |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2988 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2989 if (rettv != NULL) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2990 { |
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
|
2991 // 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
|
2992 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
|
2993 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
|
2994 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
2995 found = TRUE; |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
2996 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
2997 } |
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
|
2998 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
|
2999 { |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3000 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
|
3001 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
|
3002 |
25630
c26eb08a0df2
patch 8.2.3351: Vim9: using a function by name may delete it
Bram Moolenaar <Bram@vim.org>
parents:
25622
diff
changeset
|
3003 // 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
|
3004 // 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
|
3005 // required. |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27394
diff
changeset
|
3006 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
|
3007 || !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
|
3008 { |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
3009 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
|
3010 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
|
3011 { |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3012 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
|
3013 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
|
3014 // 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
|
3015 // 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
|
3016 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
|
3017 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
|
3018 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
|
3019 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
|
3020 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
|
3021 } |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3022 } |
3991a6df522e
patch 8.2.1527: Vim9: cannot use a function name at script level
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
3023 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3024 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3025 |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
3026 if (!found) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3027 { |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3028 if (tv == NULL) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3029 { |
24112
0346a59ed5bf
patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
24075
diff
changeset
|
3030 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
|
3031 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
|
3032 ret = FAIL; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3033 } |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3034 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
|
3035 { |
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
|
3036 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
|
3037 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
|
3038 |
25232
346002a63bc6
patch 8.2.3152: Vim9: accessing "s:" results in an error
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
3039 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
|
3040 && 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
|
3041 { |
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
|
3042 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
|
3043 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
|
3044 { |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3045 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
|
3046 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
|
3047 } |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3048 } |
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3049 |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3050 // 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
|
3051 // 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
|
3052 // declared. |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3053 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
|
3054 { |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3055 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
|
3056 && ((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
|
3057 || !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
|
3058 { |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3059 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
|
3060 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
|
3061 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3062 ++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
|
3063 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
|
3064 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
|
3065 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
|
3066 } |
25184
e495f40e4b07
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
3067 } |
28217
662d2d5db9a6
patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Bram Moolenaar <Bram@vim.org>
parents:
28152
diff
changeset
|
3068 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
|
3069 && ((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
|
3070 || !in_vim9script())) |
27924
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3071 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3072 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
|
3073 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
|
3074 { |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3075 ++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
|
3076 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
|
3077 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
|
3078 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
|
3079 } |
e6e3abc28c7a
patch 8.2.4487: Vim9: cannot compare with v:null
Bram Moolenaar <Bram@vim.org>
parents:
27811
diff
changeset
|
3080 } |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3081 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
|
3082 && ((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
|
3083 || !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
|
3084 { |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3085 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
|
3086 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
|
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 ++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
|
3089 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
|
3090 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
|
3091 } |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28218
diff
changeset
|
3092 } |
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
|
3093 } |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
21150
diff
changeset
|
3094 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
|
3095 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3096 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3097 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3098 name[len] = cc; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3099 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3100 return ret; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3101 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3102 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3103 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3104 * 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
|
3105 * 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
|
3106 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3107 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3108 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
|
3109 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3110 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
|
3111 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
|
3112 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
|
3113 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3114 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
|
3115 return; |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3116 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3117 // 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
|
3118 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
|
3119 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
|
3120 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3121 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
|
3122 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
|
3123 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3124 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
|
3125 *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
|
3126 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3127 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3128 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
|
3129 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3130 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3131 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3132 * 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
|
3133 * 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
|
3134 * 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
|
3135 * 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
|
3136 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3137 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
|
3138 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
|
3139 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3140 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
|
3141 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
|
3142 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
|
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 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
|
3145 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
|
3146 *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
|
3147 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
|
3148 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
|
3149 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
|
3150 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
|
3151 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
|
3152 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3153 // 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
|
3154 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
|
3155 if (ret != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3156 return ret; |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3157 |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3158 // 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
|
3159 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
|
3160 { |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3161 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
|
3162 if (ht != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3163 { |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23509
diff
changeset
|
3164 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
|
3165 if (ret != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3166 { |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3167 if (htp != NULL) |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3168 *htp = ht; |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3169 return ret; |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3170 } |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3171 } |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3172 } |
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3173 |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3174 // 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
|
3175 // 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
|
3176 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
|
3177 && (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
|
3178 { |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3179 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
|
3180 |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3181 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
|
3182 { |
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
|
3183 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
|
3184 ? 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
|
3185 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
|
3186 |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3187 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
|
3188 { |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3189 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
|
3190 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
|
3191 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
|
3192 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
|
3193 { |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3194 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
|
3195 *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
|
3196 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
|
3197 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3198 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3199 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3200 } |
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3201 |
22942
4759d13193fb
patch 8.2.2018: Vim9: script variable not found from lambda
Bram Moolenaar <Bram@vim.org>
parents:
22802
diff
changeset
|
3202 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
|
3203 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3204 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3205 /* |
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
|
3206 * 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
|
3207 * 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
|
3208 */ |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3209 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
|
3210 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
|
3211 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3212 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
|
3213 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3214 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
|
3215 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
|
3216 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3217 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
|
3218 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3219 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
|
3220 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3221 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
|
3222 { |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3223 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
|
3224 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3225 if (di != NULL) |
27024
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3226 { |
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3227 if (htp != NULL) |
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3228 *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
|
3229 return di; |
27024
5d851ce07caf
patch 8.2.4041: using unitialized pointer
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
3230 } |
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
|
3231 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3232 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3233 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3234 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3235 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
|
3236 } |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3237 |
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
3238 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3239 * 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
|
3240 * 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
|
3241 * 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
|
3242 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3243 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
|
3244 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
|
3245 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
|
3246 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
|
3247 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
|
3248 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
|
3249 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3250 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
|
3251 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3252 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
|
3253 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3254 // 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
|
3255 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
|
3256 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3257 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
|
3258 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
|
3259 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
|
3260 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
|
3261 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
|
3262 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
|
3263 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
|
3264 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
|
3265 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3266 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
|
3267 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3268 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3269 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
|
3270 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
|
3271 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3272 // 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
|
3273 // 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
|
3274 // 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
|
3275 // 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
|
3276 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
|
3277 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3278 // 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
|
3279 // 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
|
3280 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
|
3281 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
|
3282 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
|
3283 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3284 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
|
3285 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
|
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 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
|
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 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3290 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3291 * 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
|
3292 */ |
22531
2df99e237965
patch 8.2.1814: missing change to remove "static"
Bram Moolenaar <Bram@vim.org>
parents:
22480
diff
changeset
|
3293 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
|
3294 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
|
3295 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3296 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
|
3297 |
21979
a98211c3e14e
patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
21955
diff
changeset
|
3298 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
|
3299 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
|
3300 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3301 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3302 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3303 /* |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3304 * 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
|
3305 * 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
|
3306 * 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
|
3307 * 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
|
3308 */ |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3309 int |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3310 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
|
3311 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
|
3312 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
|
3313 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
|
3314 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
|
3315 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3316 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
|
3317 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
|
3318 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
|
3319 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
|
3320 hashitem_T *hi; |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3321 int is_global = FALSE; |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3322 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
|
3323 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3324 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
|
3325 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
|
3326 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
|
3327 { |
20326
74002d42dda0
patch 8.2.0718: gcc warning for returning pointer to local variable
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
3328 // 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
|
3329 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
|
3330 p = buffer; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3331 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3332 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3333 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
3334 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
|
3335 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
|
3336 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
|
3337 } |
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 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
|
3340 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
|
3341 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3342 // 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
|
3343 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
|
3344 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
|
3345 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
|
3346 vim_free(p); |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3347 |
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
|
3348 // 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
|
3349 // 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
|
3350 // 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
|
3351 if (res != OK) |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3352 { |
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
|
3353 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
|
3354 |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3355 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
|
3356 { |
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
|
3357 // 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
|
3358 // 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
|
3359 // 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
|
3360 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
|
3361 { |
f4061617c438
patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents:
24112
diff
changeset
|
3362 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
|
3363 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
|
3364 } |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27110
diff
changeset
|
3365 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
|
3366 res = OK; |
24049
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3367 } |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3368 } |
fc4c2beea99a
patch 8.2.2566: Vim9: Function name is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23982
diff
changeset
|
3369 |
23171
bb7531f77529
patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents:
23048
diff
changeset
|
3370 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
|
3371 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3372 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3373 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3374 * 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
|
3375 * 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
|
3376 * 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
|
3377 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3378 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
|
3379 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
|
3380 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3381 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
|
3382 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
|
3383 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3384 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
|
3385 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
|
3386 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
|
3387 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3388 // 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
|
3389 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
|
3390 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
|
3391 *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
|
3392 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3393 // "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
|
3394 // 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
|
3395 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
|
3396 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3397 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
|
3398 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
|
3399 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
|
3400 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3401 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3402 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
|
3403 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
|
3404 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
|
3405 |
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
|
3406 // 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
|
3407 // 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
|
3408 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
|
3409 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3410 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
|
3411 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
|
3412 return ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3413 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3414 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3415 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
|
3416 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3417 *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
|
3418 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
|
3419 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
|
3420 // 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
|
3421 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
|
3422 || 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
|
3423 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
|
3424 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
|
3425 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
|
3426 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
|
3427 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
|
3428 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
|
3429 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
|
3430 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
|
3431 return &vimvarht; |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19524
diff
changeset
|
3432 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
|
3433 && 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
|
3434 == 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
|
3435 { |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19524
diff
changeset
|
3436 // 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
|
3437 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
|
3438 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
|
3439 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
|
3440 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
|
3441 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3442 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
|
3443 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3444 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
|
3445 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
|
3446 return ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3447 } |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3448 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
|
3449 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3450 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3451 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3452 * 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
|
3453 * 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
|
3454 * 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
|
3455 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3456 char_u * |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3457 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
|
3458 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3459 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3460 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3461 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
|
3462 if (v == NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3463 return NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3464 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
|
3465 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3466 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3467 /* |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3468 * 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
|
3469 * 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
|
3470 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3471 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3472 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
|
3473 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3474 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
|
3475 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3476 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
|
3477 if (sv == NULL) |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3478 return; |
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
3479 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
|
3480 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
|
3481 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3482 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3483 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3484 * 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
|
3485 * 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
|
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 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3488 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
|
3489 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3490 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
|
3491 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
|
3492 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
|
3493 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
|
3494 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
|
3495 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
|
3496 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
|
3497 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
|
3498 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
|
3499 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
|
3500 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3501 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3502 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3503 * 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
|
3504 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3505 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3506 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
|
3507 { |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
3508 // 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
|
3509 // 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
|
3510 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
|
3511 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
|
3512 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3513 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
3514 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3515 * 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
|
3516 * 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
|
3517 * 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
|
3518 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3519 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3520 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
|
3521 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3522 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
|
3523 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3524 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3525 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3526 * 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
|
3527 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3528 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3529 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
|
3530 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3531 int todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3532 hashitem_T *hi; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3533 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3534 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3535 hash_lock(ht); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3536 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
|
3537 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
|
3538 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3539 if (!HASHITEM_EMPTY(hi)) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3540 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3541 --todo; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3542 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3543 // 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
|
3544 // 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
|
3545 // later. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3546 v = HI2DI(hi); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3547 if (free_val) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3548 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
|
3549 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
|
3550 vim_free(v); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3551 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3552 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3553 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
|
3554 hash_init(ht); |
17873
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3557 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3558 * 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
|
3559 * 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
|
3560 */ |
22551
86a115a80262
patch 8.2.1824: Vim9: variables at the script level escape their scope
Bram Moolenaar <Bram@vim.org>
parents:
22531
diff
changeset
|
3561 void |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3562 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
|
3563 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3564 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
|
3565 |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3566 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
|
3567 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3568 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
3569 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
|
3570 vim_free(di); |
17873
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 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3573 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3574 * 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
|
3575 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3576 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3577 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
|
3578 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3579 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3580 char_u *s; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3581 char_u numbuf[NUMBUFLEN]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3582 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3583 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
|
3584 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
|
3585 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
|
3586 vim_free(tofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3587 } |
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 static void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3590 list_one_var_a( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3591 char *prefix, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3592 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3593 int type, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3594 char_u *string, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3595 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
|
3596 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3597 // 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
|
3598 msg_start(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3599 msg_puts(prefix); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3600 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
|
3601 msg_puts((char *)name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3602 msg_putchar(' '); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3603 msg_advance(22); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3604 if (type == VAR_NUMBER) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3605 msg_putchar('#'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3606 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
|
3607 msg_putchar('*'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3608 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
|
3609 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3610 msg_putchar('['); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3611 if (*string == '[') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3612 ++string; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3613 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3614 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
|
3615 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3616 msg_putchar('{'); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3617 if (*string == '{') |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3618 ++string; |
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 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3621 msg_putchar(' '); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3622 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3623 msg_outtrans(string); |
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 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
|
3626 msg_puts("()"); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3627 if (*first) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3628 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3629 msg_clr_eos(); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3630 *first = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3631 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3632 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3635 * 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
|
3636 * 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
|
3637 * 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
|
3638 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3639 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3640 set_var( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3641 char_u *name, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3642 typval_T *tv, |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3643 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
|
3644 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3645 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
|
3646 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3647 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3648 /* |
27108
92e2e96ff559
patch 8.2.4083: Vim9: no test for "vim9script autoload' using script variable
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
3649 * 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
|
3650 * 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
|
3651 * 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
|
3652 * 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
|
3653 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3654 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3655 set_var_const( |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3656 char_u *name, |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3657 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
|
3658 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
|
3659 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
|
3660 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
|
3661 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
|
3662 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
|
3663 { |
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
|
3664 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
|
3665 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
|
3666 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
|
3667 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
|
3668 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
|
3669 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
|
3670 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
|
3671 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
|
3672 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
|
3673 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
|
3674 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
|
3675 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
|
3676 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
|
3677 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
|
3678 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3679 if (sid != 0) |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3680 { |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3681 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
|
3682 ht = &SCRIPT_VARS(sid); |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3683 varname = name; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3684 } |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3685 else |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3686 { |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3687 scriptitem_T *si; |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3688 |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
3689 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
|
3690 && 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
|
3691 && (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
|
3692 ->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
|
3693 { |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3694 // 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
|
3695 // 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
|
3696 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
|
3697 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
|
3698 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
|
3699 goto failed; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3700 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
|
3701 ht = &globvarht; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3702 } |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3703 else |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3704 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
|
3705 } |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3706 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
|
3707 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
3708 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
|
3709 goto failed; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3710 } |
27583
d4921b91542c
patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
3711 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
|
3712 || 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
|
3713 |
22266
23f5750146d9
patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents:
22240
diff
changeset
|
3714 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
|
3715 && !is_script_local |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
3716 && (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
|
3717 && (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
|
3718 && 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
|
3719 { |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3720 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
|
3721 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
|
3722 } |
30217
e0cb5fb44859
patch 9.0.0444: trying to declare g:variable gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
30124
diff
changeset
|
3723 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
|
3724 // 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
|
3725 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
|
3726 |
24279
e3dbf2e58c6a
patch 8.2.2680: Vim9: problem defining a script variable from legacy function
Bram Moolenaar <Bram@vim.org>
parents:
24264
diff
changeset
|
3727 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
|
3728 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
|
3729 { |
24426
78343859f42d
patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents:
24408
diff
changeset
|
3730 // 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
|
3731 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
|
3732 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
|
3733 goto failed; |
96e0b898d5b4
patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents:
24281
diff
changeset
|
3734 } |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
3735 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19108
diff
changeset
|
3736 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
|
3737 |
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
|
3738 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
|
3739 { |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
3740 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
|
3741 |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3742 if (import != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3743 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3744 // 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
|
3745 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
|
3746 { |
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
|
3747 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
|
3748 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
|
3749 } |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
3750 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
|
3751 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
|
3752 } |
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
|
3753 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
|
3754 { |
fae9567b8024
patch 8.2.4371: Vim9: can create a script variable from a legacy function
Bram Moolenaar <Bram@vim.org>
parents:
27583
diff
changeset
|
3755 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
|
3756 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
|
3757 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
|
3758 } |
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
|
3759 } |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3760 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3761 // 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
|
3762 if (di == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3763 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
|
3764 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3765 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
|
3766 && 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
|
3767 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3768 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3769 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
|
3770 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3771 // 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
|
3772 // converted. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3773 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
|
3774 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
|
3775 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
|
3776 tv = &bool_tv; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3777 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3778 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3779 if (di != NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3780 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3781 // 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
|
3782 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
|
3783 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3784 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
|
3785 && (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
|
3786 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3787 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
|
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 } |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3790 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3791 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
|
3792 && (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
|
3793 { |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3794 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
|
3795 goto failed; |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
diff
changeset
|
3796 } |
243985ba92b5
patch 8.2.2681: Vim9: test fails for redeclaring script variable
Bram Moolenaar <Bram@vim.org>
parents:
24279
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 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
|
3799 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3800 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
|
3801 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
|
3802 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3803 if (sv != NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3804 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3805 // 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
|
3806 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
|
3807 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
|
3808 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
|
3809 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3810 if (type == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3811 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
|
3812 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
|
3813 } |
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
|
3814 } |
29191571eceb
patch 8.2.3179: Vim9: cannot assign to an imported variable at script level
Bram Moolenaar <Bram@vim.org>
parents:
25232
diff
changeset
|
3815 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3816 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
|
3817 && 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
|
3818 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3819 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3820 else |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3821 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3822 // 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
|
3823 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
|
3824 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3825 // 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
|
3826 // 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
|
3827 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
|
3828 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
|
3829 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
|
3830 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
|
3831 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3832 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3833 // 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
|
3834 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3835 // 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
|
3836 // 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
|
3837 if (ht == &vimvarht) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3838 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3839 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
|
3840 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3841 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
|
3842 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
|
3843 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3844 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
|
3845 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3846 // 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
|
3847 // 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
|
3848 // 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
|
3849 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
|
3850 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
|
3851 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3852 else |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3853 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3854 // 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
|
3855 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
|
3856 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
|
3857 } |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3858 goto failed; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3859 } |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3860 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
|
3861 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3862 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
|
3863 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
|
3864 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
|
3865 ? '/' : '?'); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3866 #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
|
3867 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
|
3868 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3869 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
|
3870 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
|
3871 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3872 #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
|
3873 goto failed; |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3874 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3875 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
|
3876 { |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3877 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
|
3878 goto failed; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3879 } |
27811
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 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3882 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
|
3883 |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3884 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
|
3885 && 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
|
3886 { |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3887 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
|
3888 |
c0f0118b6790
patch 9.0.0460: loop variable can't be found
Bram Moolenaar <Bram@vim.org>
parents:
30217
diff
changeset
|
3889 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
|
3890 } |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3891 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3892 else |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3893 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3894 // 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
|
3895 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
|
3896 && 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
|
3897 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3898 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
|
3899 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3900 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3901 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3902 // 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
|
3903 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
|
3904 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3905 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
|
3906 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3907 } |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3908 |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
3909 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
|
3910 goto failed; |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31111
diff
changeset
|
3911 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3912 // 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
|
3913 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
|
3914 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3915 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
|
3916 goto failed; |
23450
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
3917 } |
a8e7acf71fa4
patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents:
23448
diff
changeset
|
3918 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3919 // 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
|
3920 // 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
|
3921 // autoload script. |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3922 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
|
3923 || 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
|
3924 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3925 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3926 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
|
3927 if (di == NULL) |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3928 goto failed; |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3929 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
|
3930 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
|
3931 { |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3932 vim_free(di); |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3933 goto failed; |
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 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
|
3936 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
|
3937 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
|
3938 |
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3939 // 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
|
3940 // 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
|
3941 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
|
3942 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
|
3943 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
|
3944 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
|
3945 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3946 |
27811
27956f5e263c
patch 8.2.4431: unnecessary condition when assigning to a variable
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
3947 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
|
3948 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
|
3949 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
|
3950 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3951 { |
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
|
3952 *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
|
3953 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
|
3954 init_tv(tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3955 } |
26482
b115b552071f
patch 8.2.3771: Vim9: accessing freed memory when checking type
Bram Moolenaar <Bram@vim.org>
parents:
26450
diff
changeset
|
3956 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
|
3957 |
23458
d2b1269c2c68
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents:
23450
diff
changeset
|
3958 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
|
3959 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
|
3960 |
23299
d5919c5fd3dc
patch 8.2.2195: failing tests for :const
Bram Moolenaar <Bram@vim.org>
parents:
23297
diff
changeset
|
3961 // ":const var = value" locks the value |
d5919c5fd3dc
patch 8.2.2195: failing tests for :const
Bram Moolenaar <Bram@vim.org>
parents:
23297
diff
changeset
|
3962 // ":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
|
3963 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
|
3964 // 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
|
3965 // 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
|
3966 // 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
|
3967 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
|
3968 |
22240
88927d5f275d
patch 8.2.1669: Vim9: memory leak when storing a value fails
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
3969 failed: |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
3970 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
|
3971 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
|
3972 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
|
3973 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3974 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3975 /* |
23295
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3976 * 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
|
3977 * - 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
|
3978 * - 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
|
3979 * - 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
|
3980 */ |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3981 int |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3982 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
|
3983 { |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3984 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
|
3985 || 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
|
3986 || 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
|
3987 return FAIL; |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3988 return OK; |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3989 } |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3990 |
d9ae7dd3a0f2
patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents:
23239
diff
changeset
|
3991 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3992 * 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
|
3993 * 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
|
3994 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3995 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3996 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
|
3997 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3998 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
|
3999 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4000 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
|
4001 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
|
4002 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4003 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
|
4004 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
|
4005 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4006 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4007 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
|
4008 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4009 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
|
4010 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
|
4011 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4012 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
|
4013 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
|
4014 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4015 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4016 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4017 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4018 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4019 /* |
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
|
4020 * 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
|
4021 * 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
|
4022 */ |
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
|
4023 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
|
4024 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
|
4025 { |
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
|
4026 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
|
4027 { |
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
|
4028 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
|
4029 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
|
4030 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
|
4031 } |
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
|
4032 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
|
4033 } |
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
|
4034 |
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
|
4035 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4036 * 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
|
4037 * 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
|
4038 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4039 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4040 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
|
4041 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4042 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
|
4043 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4044 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
|
4045 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
|
4046 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4047 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
|
4048 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
|
4049 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4050 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4051 return FALSE; |
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 |
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 * 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
|
4056 * 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
|
4057 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4058 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
|
4059 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
|
4060 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
|
4061 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
|
4062 { |
24264
db5eaad456cc
patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents:
24238
diff
changeset
|
4063 // 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
|
4064 // 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
|
4065 // 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
|
4066 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
|
4067 || (!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
|
4068 && !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
|
4069 ? 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
|
4070 && 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
|
4071 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4072 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
|
4073 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4074 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4075 // 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
|
4076 // 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
|
4077 // below. |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4078 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
|
4079 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4080 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
|
4081 name); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4082 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4083 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4084 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4085 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4086 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4087 /* |
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
|
4088 * 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
|
4089 * 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
|
4090 * "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
|
4091 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4092 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
|
4093 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
|
4094 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4095 if (lock & VAR_LOCKED) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4096 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4097 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
|
4098 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
|
4099 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4100 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
|
4101 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
|
4102 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4103 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4104 if (lock & VAR_FIXED) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4105 { |
26624
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4106 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
|
4107 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
|
4108 else |
bdf11d8e3df3
patch 8.2.3841: Vim9: outdated TODO items, disabled tests that work
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4109 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
|
4110 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
|
4111 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4112 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4113 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4114 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4115 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4116 /* |
23233
657216220293
patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents:
23223
diff
changeset
|
4117 * 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
|
4118 * 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
|
4119 * 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
|
4120 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4121 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
|
4122 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
|
4123 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4124 char_u *p; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4125 |
26238
14b4c778b61e
patch 8.2.3650: Vim9: for loop variable can be a list member
Bram Moolenaar <Bram@vim.org>
parents:
26195
diff
changeset
|
4126 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
|
4127 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
|
4128 && !(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
|
4129 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4130 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
|
4131 return FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4132 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4133 return TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4134 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4135 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4136 /* |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4137 * 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
|
4138 * 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
|
4139 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4140 static void |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4141 get_var_from( |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4142 char_u *varname, |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4143 typval_T *rettv, |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4144 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
|
4145 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
|
4146 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
|
4147 win_T *win, |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4148 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
|
4149 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4150 dictitem_T *v; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4151 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
|
4152 switchwin_T switchwin; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4153 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
|
4154 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
|
4155 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4156 ++emsg_off; |
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 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
|
4159 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
|
4160 |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4161 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
|
4162 && (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
|
4163 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4164 // 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
|
4165 // 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
|
4166 // autocommands get blocked. |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4167 // 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
|
4168 // 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
|
4169 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
|
4170 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
|
4171 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4172 // 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
|
4173 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
|
4174 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4175 buf_T *save_curbuf = curbuf; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4176 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4177 // 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
|
4178 if (do_change_curbuf) |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4179 curbuf = buf; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4180 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4181 if (varname[1] == NUL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4182 { |
29448
8f1e16995118
patch 9.0.0066: switching window uneccarily when getting buffer options
Bram Moolenaar <Bram@vim.org>
parents:
29320
diff
changeset
|
4183 // 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
|
4184 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
|
4185 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4186 if (opts != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4187 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4188 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
|
4189 done = TRUE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4190 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4191 } |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4192 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
|
4193 // Local option |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4194 done = TRUE; |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4195 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4196 curbuf = save_curbuf; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4197 } |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4198 else if (*varname == NUL) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4199 { |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4200 // 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
|
4201 if (htname == 'b') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4202 v = &buf->b_bufvar; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4203 else if (htname == 'w') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4204 v = &win->w_winvar; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4205 else |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4206 v = &tp->tp_winvar; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4207 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
|
4208 done = TRUE; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4209 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4210 else |
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 hashtab_T *ht; |
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 if (htname == 'b') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4215 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
|
4216 else if (htname == 'w') |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4217 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
|
4218 else |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4219 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
|
4220 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4221 // Look up the variable. |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4222 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
|
4223 if (v != 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 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
|
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4229 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4230 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4231 if (need_switch_win) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4232 // 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
|
4233 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
|
4234 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4235 |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4236 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
|
4237 // use the default value |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4238 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
|
4239 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4240 --emsg_off; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4241 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4242 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4243 /* |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4244 * getwinvar() and gettabwinvar() |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4245 */ |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4246 static void |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4247 getwinvar( |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4248 typval_T *argvars, |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4249 typval_T *rettv, |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4250 int off) // 1 for gettabwinvar() |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4251 { |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4252 char_u *varname; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4253 tabpage_T *tp; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4254 win_T *win; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4255 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4256 if (off == 1) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4257 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
|
4258 else |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4259 tp = curtab; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4260 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
|
4261 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
|
4262 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4263 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
|
4264 } |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4265 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4266 /* |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4267 * 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
|
4268 */ |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4269 static void |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4270 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
|
4271 { |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4272 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
|
4273 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
|
4274 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
|
4275 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
|
4276 |
23483
ce7d6b461660
patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
4277 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
|
4278 { |
29497
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4279 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
|
4280 { |
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4281 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
|
4282 return; |
9908c07ccb56
patch 9.0.0090: no error when assigning bool to a string option
Bram Moolenaar <Bram@vim.org>
parents:
29448
diff
changeset
|
4283 } |
23483
ce7d6b461660
patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents:
23458
diff
changeset
|
4284 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
|
4285 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
|
4286 } |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4287 else |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4288 { |
198ad7ef2420
patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents:
23483
diff
changeset
|
4289 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
|
4290 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
|
4291 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
|
4292 } |
21879
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4293 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
|
4294 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
|
4295 } |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4296 |
172b1746489c
patch 8.2.1489: Vim9: error when setting an option with setbufvar()
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
4297 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4298 * "setwinvar()" and "settabwinvar()" functions |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4299 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4300 static void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4301 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
|
4302 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4303 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
|
4304 switchwin_T switchwin; |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4305 int need_switch_win; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4306 char_u *varname, *winvarname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4307 typval_T *varp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4308 tabpage_T *tp = NULL; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4309 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4310 if (check_secure()) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4311 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4312 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4313 if (off == 1) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4314 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
|
4315 else |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4316 tp = curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4317 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
|
4318 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
|
4319 varp = &argvars[off + 2]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4320 |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4321 if (win == NULL || varname == NULL || varp == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4322 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4323 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4324 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
|
4325 if (!need_switch_win |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4326 || 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
|
4327 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4328 if (*varname == '&') |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4329 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
|
4330 else |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4331 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4332 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
|
4333 if (winvarname != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4334 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4335 STRCPY(winvarname, "w:"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4336 STRCPY(winvarname + 2, varname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4337 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
|
4338 vim_free(winvarname); |
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 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4341 } |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4342 if (need_switch_win) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4343 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
|
4344 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4345 |
17885
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4346 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4347 * 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
|
4348 * 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
|
4349 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4350 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4351 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
|
4352 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4353 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
|
4354 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
|
4355 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
|
4356 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
|
4357 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
|
4358 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
|
4359 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4360 |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4361 /* |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4362 * 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
|
4363 */ |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4364 void |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4365 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
|
4366 { |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4367 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
|
4368 |
26723
c3cffd372c6f
patch 8.2.3890: Vim9: type check for using v: variables is basic
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
4369 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
|
4370 // 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
|
4371 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
|
4372 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
|
4373 } |
5e2d8840da11
patch 8.1.1939: code for handling v: variables in generic eval file
Bram Moolenaar <Bram@vim.org>
parents:
17873
diff
changeset
|
4374 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4375 int |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4376 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
|
4377 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
4378 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
|
4379 char_u *name; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4380 char_u *tofree; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4381 typval_T tv; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4382 int len = 0; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4383 int n = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4384 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4385 // 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
|
4386 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
|
4387 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
|
4388 if (len > 0) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4389 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4390 if (tofree != NULL) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4391 name = tofree; |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26978
diff
changeset
|
4392 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
|
4393 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
|
4394 if (n) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4395 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4396 // 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
|
4397 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
|
4398 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
|
4399 FALSE) == OK); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4400 if (n) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4401 clear_tv(&tv); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4402 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4403 } |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
4404 if (*arg != NUL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4405 n = FALSE; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4406 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4407 vim_free(tofree); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4408 return n; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4409 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4410 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4411 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
|
4412 #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
|
4413 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
|
4414 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
|
4415 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
|
4416 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4417 int |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4418 alloc_redir_lval(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4419 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4420 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
|
4421 if (redir_lval == NULL) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4422 return FAIL; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4423 return OK; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4424 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4425 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4426 void |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4427 clear_redir_lval(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4428 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4429 VIM_CLEAR(redir_lval); |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4430 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4431 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4432 void |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4433 init_redir_ga(void) |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4434 { |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27024
diff
changeset
|
4435 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
|
4436 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4437 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4438 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4439 * 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
|
4440 * 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
|
4441 * 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
|
4442 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4443 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4444 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
|
4445 { |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
4446 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
|
4447 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
|
4448 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4449 // 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
|
4450 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
|
4451 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
4452 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
|
4453 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4454 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4455 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4456 // 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
|
4457 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
|
4458 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
|
4459 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4460 |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4461 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
|
4462 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4463 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
|
4464 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4465 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4466 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4467 // 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
|
4468 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
|
4469 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4470 // 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
|
4471 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
|
4472 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
|
4473 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
|
4474 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4475 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
|
4476 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
|
4477 // 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
|
4478 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
|
4479 else |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26861
diff
changeset
|
4480 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
|
4481 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
|
4482 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
|
4483 return FAIL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4484 } |
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 // 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
|
4487 // string |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
4488 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
|
4489 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
|
4490 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
|
4491 if (append) |
22691
dda110a14be4
patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents:
22667
diff
changeset
|
4492 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
|
4493 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
|
4494 else |
22691
dda110a14be4
patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents:
22667
diff
changeset
|
4495 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
|
4496 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
|
4497 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
|
4498 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
|
4499 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4500 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
|
4501 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
|
4502 return FAIL; |
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 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4505 return OK; |
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 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4508 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4509 * 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
|
4510 * 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
|
4511 * 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
|
4512 * 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
|
4513 * :redir => foo |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4514 * :let foo |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4515 * :redir END |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4516 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4517 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4518 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
|
4519 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4520 int len; |
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 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
|
4523 return; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4524 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4525 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
|
4526 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
|
4527 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4528 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
|
4529 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4530 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
|
4531 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4532 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
|
4533 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
|
4534 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4535 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4536 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
|
4537 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4538 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4539 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4540 * 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
|
4541 * 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
|
4542 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4543 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4544 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
|
4545 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4546 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
|
4547 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4548 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
|
4549 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4550 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
|
4551 return; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4552 } |
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 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
|
4555 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4556 // 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
|
4557 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
|
4558 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4559 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
|
4560 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
|
4561 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
|
4562 // 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
|
4563 // have changed. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4564 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
|
4565 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
|
4566 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
|
4567 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
|
4568 (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
|
4569 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
|
4570 } |
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 // 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
|
4573 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
|
4574 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4575 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
|
4576 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4577 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
|
4578 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17893
diff
changeset
|
4579 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4580 /* |
24490
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4581 * 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
|
4582 */ |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4583 char_u * |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4584 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
|
4585 { |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4586 char_u *res; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4587 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4588 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
|
4589 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
|
4590 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
|
4591 return res; |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4592 } |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4593 |
08050e45bd06
patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents:
24482
diff
changeset
|
4594 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4595 * "gettabvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4596 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4597 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4598 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
|
4599 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4600 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
|
4601 tabpage_T *tp; |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4602 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
|
4603 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4604 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
|
4605 && (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
|
4606 || 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
|
4607 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4608 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4609 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
|
4610 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
|
4611 if (tp != NULL) |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4612 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
|
4613 : tp->tp_firstwin; |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4614 |
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4615 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
|
4616 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4617 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4618 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4619 * "gettabwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4620 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4621 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4622 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
|
4623 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4624 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
|
4625 && (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
|
4626 || 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
|
4627 || 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
|
4628 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4629 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4630 getwinvar(argvars, rettv, 1); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4631 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4632 |
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 * "getwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4635 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4636 void |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4637 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
|
4638 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4639 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
|
4640 && (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
|
4641 || 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
|
4642 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4643 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4644 getwinvar(argvars, rettv, 0); |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4645 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4646 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4647 /* |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4648 * "getbufvar()" function |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4649 */ |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4650 void |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4651 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
|
4652 { |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4653 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
|
4654 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
|
4655 |
25348
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4656 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
|
4657 && (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
|
4658 || 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
|
4659 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4660 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4661 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
|
4662 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
|
4663 |
28684
6d55e6c9cdb5
patch 8.2.4866: duplicate code in "get" functions
Bram Moolenaar <Bram@vim.org>
parents:
28633
diff
changeset
|
4664 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
|
4665 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4666 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4667 /* |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4668 * "settabvar()" function |
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 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4671 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
|
4672 { |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4673 tabpage_T *save_curtab; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4674 tabpage_T *tp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4675 char_u *varname, *tabvarname; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4676 typval_T *varp; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4677 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4678 if (check_secure()) |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4679 return; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4680 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4681 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
|
4682 && (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
|
4683 || 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
|
4684 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4685 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4686 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
|
4687 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
|
4688 varp = &argvars[2]; |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4689 |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4690 if (varname == NULL || varp == NULL || tp == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4691 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4692 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4693 save_curtab = curtab; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4694 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
|
4695 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4696 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
|
4697 if (tabvarname != NULL) |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4698 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4699 STRCPY(tabvarname, "t:"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4700 STRCPY(tabvarname + 2, varname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4701 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
|
4702 vim_free(tabvarname); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4703 } |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4704 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4705 // Restore current tabpage |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4706 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
|
4707 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
|
4708 } |
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 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4711 * "settabwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4712 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4713 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4714 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
|
4715 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4716 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
|
4717 && (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
|
4718 || 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
|
4719 || 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
|
4720 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4721 |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4722 setwinvar(argvars, 1); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4723 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4724 |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4725 /* |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4726 * "setwinvar()" function |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4727 */ |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4728 void |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4729 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
|
4730 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4731 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
|
4732 && (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
|
4733 || 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
|
4734 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25298
diff
changeset
|
4735 |
19049
e47b04b01793
patch 8.2.0085: dead code in builtin functions
Bram Moolenaar <Bram@vim.org>
parents:
18477
diff
changeset
|
4736 setwinvar(argvars, 0); |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4737 } |
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4738 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4739 /* |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4740 * "setbufvar()" function |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4741 */ |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4742 void |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4743 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
|
4744 { |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4745 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
|
4746 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
|
4747 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
|
4748 |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4749 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
|
4750 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
|
4751 |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4752 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
|
4753 && (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
|
4754 || 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
|
4755 return; |
75031a22be39
patch 8.2.3211: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25328
diff
changeset
|
4756 |
17893
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4757 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
|
4758 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
|
4759 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
|
4760 |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4761 if (buf == NULL || varname == NULL || varp == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4762 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4763 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4764 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
|
4765 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4766 aco_save_T aco; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4767 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4768 // 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
|
4769 aucmd_prepbuf(&aco, buf); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4770 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
|
4771 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4772 // 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
|
4773 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
|
4774 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4775 // reset notion of buffer |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4776 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
|
4777 } |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4778 } |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4779 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4780 { |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4781 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
|
4782 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
|
4783 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4784 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
|
4785 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4786 curbuf = buf; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4787 STRCPY(bufvarname, "b:"); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4788 STRCPY(bufvarname + 2, varname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4789 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
|
4790 vim_free(bufvarname); |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4791 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
|
4792 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4793 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4794 } |
e4d3b6c466d4
patch 8.1.1943: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17887
diff
changeset
|
4795 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4796 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4797 * 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
|
4798 * 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
|
4799 * 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
|
4800 * "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
|
4801 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4802 callback_T |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4803 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
|
4804 { |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4805 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
|
4806 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
|
4807 |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4808 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
|
4809 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
|
4810 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4811 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
|
4812 ++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
|
4813 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
|
4814 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4815 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4816 { |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4817 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
|
4818 && 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
|
4819 r = FAIL; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4820 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
|
4821 { |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4822 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
|
4823 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
|
4824 { |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4825 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
|
4826 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
|
4827 { |
31313
b6bef244837e
patch 9.0.0990: callback name argument is changed by setqflist()
Bram Moolenaar <Bram@vim.org>
parents:
31263
diff
changeset
|
4828 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
|
4829 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
|
4830 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26624
diff
changeset
|
4831 } |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4832 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
|
4833 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4834 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
|
4835 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
|
4836 else |
19609
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4837 r = FAIL; |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4838 |
fe827d6267c2
patch 8.2.0361: internal error when using "0" for a callback
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
4839 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
|
4840 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4841 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
|
4842 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
|
4843 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4844 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4845 return res; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4846 } |
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 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4849 * 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
|
4850 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4851 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4852 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
|
4853 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4854 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
|
4855 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4856 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
|
4857 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
|
4858 ++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
|
4859 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4860 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4861 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4862 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
|
4863 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
|
4864 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
|
4865 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4866 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4867 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4868 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4869 * 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
|
4870 * 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
|
4871 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4872 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4873 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
|
4874 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4875 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
|
4876 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4877 // 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
|
4878 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
|
4879 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
|
4880 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4881 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4882 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4883 // 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
|
4884 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
|
4885 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
|
4886 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4887 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
|
4888 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4889 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4890 /* |
21409
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4891 * 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
|
4892 */ |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4893 void |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4894 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
|
4895 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4896 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
|
4897 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
|
4898 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4899 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
|
4900 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
|
4901 ++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
|
4902 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4903 else |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4904 { |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4905 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
|
4906 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
|
4907 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
|
4908 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4909 } |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4910 |
2c40e60017a8
patch 8.2.1255: cannot use a lambda with quickfix functions
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4911 /* |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4912 * 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
|
4913 * 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
|
4914 * 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
|
4915 */ |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4916 void |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4917 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
|
4918 { |
27362
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4919 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
|
4920 char_u *p; |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4921 imported_T *import; |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4922 |
27362
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4923 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
|
4924 || (!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
|
4925 && (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
|
4926 return; |
27362
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4927 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
|
4928 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
|
4929 else |
2ca6dd1f62af
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Bram Moolenaar <Bram@vim.org>
parents:
27338
diff
changeset
|
4930 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
|
4931 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
|
4932 if (p == NULL) |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4933 return; |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4934 |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27690
diff
changeset
|
4935 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
|
4936 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
|
4937 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4938 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4939 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
|
4940 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
|
4941 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4942 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4943 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
|
4944 if (newname == NULL) |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4945 return; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4946 |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4947 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
|
4948 { |
31600
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4949 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
|
4950 cb->cb_name = newname; |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4951 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
|
4952 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
|
4953 } |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4954 else |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4955 { |
f1d5ad2b978e
patch 9.0.1132: code is indented more than needed
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
4956 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
|
4957 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
|
4958 } |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4959 } |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4960 |
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27277
diff
changeset
|
4961 /* |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4962 * 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
|
4963 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4964 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4965 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
|
4966 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4967 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
|
4968 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4969 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
|
4970 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
|
4971 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4972 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
|
4973 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
|
4974 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
|
4975 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4976 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
|
4977 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
|
4978 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4979 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
|
4980 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
4981 |
17873
d50a5faa75bd
patch 8.1.1933: the eval.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4982 #endif // FEAT_EVAL |