Skip to content

Commit

Permalink
Merge remote-tracking branch 'vim/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ichizok committed Mar 28, 2021
2 parents ef048ed + f49a1fc commit 7d55a41
Show file tree
Hide file tree
Showing 38 changed files with 1,043 additions and 241 deletions.
14 changes: 11 additions & 3 deletions runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ Changing the order of items in a list: >

For loop ~

The |:for| loop executes commands for each item in a list. A variable is set
to each item in the list in sequence. Example: >
The |:for| loop executes commands for each item in a List, String or Blob.
A variable is set to each item in sequence. Example with a List: >
:for item in mylist
: call Doit(item)
:endfor
Expand All @@ -457,7 +457,7 @@ If all you want to do is modify each item in the list then the |map()|
function will be a simpler method than a for loop.

Just like the |:let| command, |:for| also accepts a list of variables. This
requires the argument to be a list of lists. >
requires the argument to be a List of Lists. >
:for [lnum, col] in [[1, 3], [2, 8], [3, 0]]
: call Doit(lnum, col)
:endfor
Expand All @@ -473,6 +473,14 @@ It is also possible to put remaining items in a List variable: >
: endif
:endfor

For a Blob one byte at a time is used.

For a String one character, including any composing characters, is used as a
String. Example: >
for c in text
echo 'This character is ' .. c
endfor


List functions ~
*E714*
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/textprop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ prop_find({props} [, {direction}])
Search for a text property as specified with {props}:
id property with this ID
type property with this type name
both "id" and "type" must both match
bufnr buffer to search in; when present a
start position with "lnum" and "col"
must be given; when omitted the
Expand All @@ -187,6 +188,7 @@ prop_find({props} [, {direction}])
skipstart do not look for a match at the start
position

A property matches when either "id" or "type" matches.
{direction} can be "f" for forward and "b" for backward. When
omitted forward search is performed.

Expand Down
5 changes: 5 additions & 0 deletions src/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4946,6 +4946,11 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
// Don't open a file in restricted mode.
if (check_restricted() || check_secure())
return;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;

fname = tv_get_string(&argvars[0]);
if (argvars[1].v_type == VAR_STRING)
opt = tv_get_string_buf(&argvars[1], buf);
Expand Down
6 changes: 5 additions & 1 deletion src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,8 @@ EXTERN char e_text_found_after_enddef_str[]
EXTERN char e_string_required_for_argument_nr[]
INIT(= N_("E1174: String required for argument %d"));
EXTERN char e_non_empty_string_required_for_argument_nr[]
INIT(= N_("E1142: Non-empty string required for argument %d"));
INIT(= N_("E1175: Non-empty string required for argument %d"));
EXTERN char e_misplaced_command_modifier[]
INIT(= N_("E1176: Misplaced command modifier"));
EXTERN char e_for_loop_on_str_not_supported[]
INIT(= N_("E1177: For loop on %s not supported"));
43 changes: 39 additions & 4 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ typedef struct
list_T *fi_list; // list being used
int fi_bi; // index of blob
blob_T *fi_blob; // blob being used
char_u *fi_string; // copy of string being used
int fi_byte_idx; // byte index in fi_string
} forinfo_T;

static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op);
Expand Down Expand Up @@ -1738,6 +1740,14 @@ eval_for_line(
}
clear_tv(&tv);
}
else if (tv.v_type == VAR_STRING)
{
fi->fi_byte_idx = 0;
fi->fi_string = tv.vval.v_string;
tv.vval.v_string = NULL;
if (fi->fi_string == NULL)
fi->fi_string = vim_strsave((char_u *)"");
}
else
{
emsg(_(e_listreq));
Expand Down Expand Up @@ -1790,7 +1800,25 @@ next_for_item(void *fi_void, char_u *arg)
tv.vval.v_number = blob_get(fi->fi_blob, fi->fi_bi);
++fi->fi_bi;
return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
fi->fi_varcount, flag, NULL) == OK;
fi->fi_varcount, flag, NULL) == OK;
}

if (fi->fi_string != NULL)
{
typval_T tv;
int len;

len = mb_ptr2len(fi->fi_string + fi->fi_byte_idx);
if (len == 0)
return FALSE;
tv.v_type = VAR_STRING;
tv.v_lock = VAR_FIXED;
tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len);
fi->fi_byte_idx += len;
result = ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
fi->fi_varcount, flag, NULL) == OK;
vim_free(tv.vval.v_string);
return result;
}

item = fi->fi_lw.lw_item;
Expand All @@ -1800,7 +1828,7 @@ next_for_item(void *fi_void, char_u *arg)
{
fi->fi_lw.lw_item = item->li_next;
result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon,
fi->fi_varcount, flag, NULL) == OK);
fi->fi_varcount, flag, NULL) == OK);
}
return result;
}
Expand All @@ -1813,13 +1841,17 @@ free_for_info(void *fi_void)
{
forinfo_T *fi = (forinfo_T *)fi_void;

if (fi != NULL && fi->fi_list != NULL)
if (fi == NULL)
return;
if (fi->fi_list != NULL)
{
list_rem_watch(fi->fi_list, &fi->fi_lw);
list_unref(fi->fi_list);
}
if (fi != NULL && fi->fi_blob != NULL)
else if (fi->fi_blob != NULL)
blob_unref(fi->fi_blob);
else
vim_free(fi->fi_string);
vim_free(fi);
}

Expand Down Expand Up @@ -5266,6 +5298,9 @@ var2fpos(
return &pos;
}

if (in_vim9script() && check_for_string_arg(varp, 0) == FAIL)
return NULL;

name = tv_get_string_chk(varp);
if (name == NULL)
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/evalbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ find_buffer(typval_T *avar)

if (avar->v_type == VAR_NUMBER)
buf = buflist_findnr((int)avar->vval.v_number);
else if (in_vim9script() && check_for_string_arg(avar, 0) == FAIL)
return NULL;
else if (avar->v_type == VAR_STRING && avar->vval.v_string != NULL)
{
buf = buflist_findname_exp(avar->vval.v_string);
Expand Down
20 changes: 18 additions & 2 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2323,8 +2323,12 @@ f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
}
else
{
char_u *mesg = tv_get_string_chk(&argvars[0]);
char_u *mesg;

if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;

mesg = tv_get_string_chk(&argvars[0]);
if (mesg != NULL)
// empty string removes the balloon
post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL);
Expand All @@ -2338,8 +2342,11 @@ f_balloon_split(typval_T *argvars, typval_T *rettv UNUSED)
{
if (rettv_list_alloc(rettv) == OK)
{
char_u *msg = tv_get_string_chk(&argvars[0]);
char_u *msg;

if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;
msg = tv_get_string_chk(&argvars[0]);
if (msg != NULL)
{
pumitem_T *array;
Expand Down Expand Up @@ -2514,6 +2521,8 @@ f_changenr(typval_T *argvars UNUSED, typval_T *rettv)
static void
f_char2nr(typval_T *argvars, typval_T *rettv)
{
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;
if (has_mbyte)
{
int utf8 = 0;
Expand Down Expand Up @@ -2678,11 +2687,16 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
char_u *typestr;
int error = FALSE;

if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;

message = tv_get_string_chk(&argvars[0]);
if (message == NULL)
error = TRUE;
if (argvars[1].v_type != VAR_UNKNOWN)
{
if (in_vim9script() && check_for_string_arg(argvars, 1) == FAIL)
return;
buttons = tv_get_string_buf_chk(&argvars[1], buf);
if (buttons == NULL)
error = TRUE;
Expand All @@ -2691,6 +2705,8 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
def = (int)tv_get_number_chk(&argvars[2], &error);
if (argvars[3].v_type != VAR_UNKNOWN)
{
if (in_vim9script() && check_for_string_arg(argvars, 3) == FAIL)
return;
typestr = tv_get_string_buf_chk(&argvars[3], buf2);
if (typestr == NULL)
error = TRUE;
Expand Down
7 changes: 5 additions & 2 deletions src/evalvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,11 @@ ex_let(exarg_T *eap)
{
if (vim9script)
{
// Vim9 declaration ":var name: type"
arg = vim9_declare_scriptvar(eap, arg);
if (!ends_excmd2(eap->cmd, skipwhite(argend)))
semsg(_(e_trailing_arg), argend);
else
// Vim9 declaration ":var name: type"
arg = vim9_declare_scriptvar(eap, arg);
}
else
{
Expand Down
Loading

0 comments on commit 7d55a41

Please sign in to comment.