Skip to content

Commit 7d55a41

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents ef048ed + f49a1fc commit 7d55a41

38 files changed

+1043
-241
lines changed

runtime/doc/eval.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ Changing the order of items in a list: >
439439

440440
For loop ~
441441

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

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

476+
For a Blob one byte at a time is used.
477+
478+
For a String one character, including any composing characters, is used as a
479+
String. Example: >
480+
for c in text
481+
echo 'This character is ' .. c
482+
endfor
483+
476484

477485
List functions ~
478486
*E714*

runtime/doc/textprop.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ prop_find({props} [, {direction}])
175175
Search for a text property as specified with {props}:
176176
id property with this ID
177177
type property with this type name
178+
both "id" and "type" must both match
178179
bufnr buffer to search in; when present a
179180
start position with "lnum" and "col"
180181
must be given; when omitted the
@@ -187,6 +188,7 @@ prop_find({props} [, {direction}])
187188
skipstart do not look for a match at the start
188189
position
189190

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

src/channel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,6 +4946,11 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
49464946
// Don't open a file in restricted mode.
49474947
if (check_restricted() || check_secure())
49484948
return;
4949+
if (in_vim9script()
4950+
&& (check_for_string_arg(argvars, 0) == FAIL
4951+
|| check_for_string_arg(argvars, 1) == FAIL))
4952+
return;
4953+
49494954
fname = tv_get_string(&argvars[0]);
49504955
if (argvars[1].v_type == VAR_STRING)
49514956
opt = tv_get_string_buf(&argvars[1], buf);

src/errors.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,8 @@ EXTERN char e_text_found_after_enddef_str[]
386386
EXTERN char e_string_required_for_argument_nr[]
387387
INIT(= N_("E1174: String required for argument %d"));
388388
EXTERN char e_non_empty_string_required_for_argument_nr[]
389-
INIT(= N_("E1142: Non-empty string required for argument %d"));
389+
INIT(= N_("E1175: Non-empty string required for argument %d"));
390+
EXTERN char e_misplaced_command_modifier[]
391+
INIT(= N_("E1176: Misplaced command modifier"));
392+
EXTERN char e_for_loop_on_str_not_supported[]
393+
INIT(= N_("E1177: For loop on %s not supported"));

src/eval.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ typedef struct
4141
list_T *fi_list; // list being used
4242
int fi_bi; // index of blob
4343
blob_T *fi_blob; // blob being used
44+
char_u *fi_string; // copy of string being used
45+
int fi_byte_idx; // byte index in fi_string
4446
} forinfo_T;
4547

4648
static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op);
@@ -1738,6 +1740,14 @@ eval_for_line(
17381740
}
17391741
clear_tv(&tv);
17401742
}
1743+
else if (tv.v_type == VAR_STRING)
1744+
{
1745+
fi->fi_byte_idx = 0;
1746+
fi->fi_string = tv.vval.v_string;
1747+
tv.vval.v_string = NULL;
1748+
if (fi->fi_string == NULL)
1749+
fi->fi_string = vim_strsave((char_u *)"");
1750+
}
17411751
else
17421752
{
17431753
emsg(_(e_listreq));
@@ -1790,7 +1800,25 @@ next_for_item(void *fi_void, char_u *arg)
17901800
tv.vval.v_number = blob_get(fi->fi_blob, fi->fi_bi);
17911801
++fi->fi_bi;
17921802
return ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
1793-
fi->fi_varcount, flag, NULL) == OK;
1803+
fi->fi_varcount, flag, NULL) == OK;
1804+
}
1805+
1806+
if (fi->fi_string != NULL)
1807+
{
1808+
typval_T tv;
1809+
int len;
1810+
1811+
len = mb_ptr2len(fi->fi_string + fi->fi_byte_idx);
1812+
if (len == 0)
1813+
return FALSE;
1814+
tv.v_type = VAR_STRING;
1815+
tv.v_lock = VAR_FIXED;
1816+
tv.vval.v_string = vim_strnsave(fi->fi_string + fi->fi_byte_idx, len);
1817+
fi->fi_byte_idx += len;
1818+
result = ex_let_vars(arg, &tv, TRUE, fi->fi_semicolon,
1819+
fi->fi_varcount, flag, NULL) == OK;
1820+
vim_free(tv.vval.v_string);
1821+
return result;
17941822
}
17951823

17961824
item = fi->fi_lw.lw_item;
@@ -1800,7 +1828,7 @@ next_for_item(void *fi_void, char_u *arg)
18001828
{
18011829
fi->fi_lw.lw_item = item->li_next;
18021830
result = (ex_let_vars(arg, &item->li_tv, TRUE, fi->fi_semicolon,
1803-
fi->fi_varcount, flag, NULL) == OK);
1831+
fi->fi_varcount, flag, NULL) == OK);
18041832
}
18051833
return result;
18061834
}
@@ -1813,13 +1841,17 @@ free_for_info(void *fi_void)
18131841
{
18141842
forinfo_T *fi = (forinfo_T *)fi_void;
18151843

1816-
if (fi != NULL && fi->fi_list != NULL)
1844+
if (fi == NULL)
1845+
return;
1846+
if (fi->fi_list != NULL)
18171847
{
18181848
list_rem_watch(fi->fi_list, &fi->fi_lw);
18191849
list_unref(fi->fi_list);
18201850
}
1821-
if (fi != NULL && fi->fi_blob != NULL)
1851+
else if (fi->fi_blob != NULL)
18221852
blob_unref(fi->fi_blob);
1853+
else
1854+
vim_free(fi->fi_string);
18231855
vim_free(fi);
18241856
}
18251857

@@ -5266,6 +5298,9 @@ var2fpos(
52665298
return &pos;
52675299
}
52685300

5301+
if (in_vim9script() && check_for_string_arg(varp, 0) == FAIL)
5302+
return NULL;
5303+
52695304
name = tv_get_string_chk(varp);
52705305
if (name == NULL)
52715306
return NULL;

src/evalbuffer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ find_buffer(typval_T *avar)
8888

8989
if (avar->v_type == VAR_NUMBER)
9090
buf = buflist_findnr((int)avar->vval.v_number);
91+
else if (in_vim9script() && check_for_string_arg(avar, 0) == FAIL)
92+
return NULL;
9193
else if (avar->v_type == VAR_STRING && avar->vval.v_string != NULL)
9294
{
9395
buf = buflist_findname_exp(avar->vval.v_string);

src/evalfunc.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,8 +2323,12 @@ f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
23232323
}
23242324
else
23252325
{
2326-
char_u *mesg = tv_get_string_chk(&argvars[0]);
2326+
char_u *mesg;
23272327

2328+
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
2329+
return;
2330+
2331+
mesg = tv_get_string_chk(&argvars[0]);
23282332
if (mesg != NULL)
23292333
// empty string removes the balloon
23302334
post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL);
@@ -2338,8 +2342,11 @@ f_balloon_split(typval_T *argvars, typval_T *rettv UNUSED)
23382342
{
23392343
if (rettv_list_alloc(rettv) == OK)
23402344
{
2341-
char_u *msg = tv_get_string_chk(&argvars[0]);
2345+
char_u *msg;
23422346

2347+
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
2348+
return;
2349+
msg = tv_get_string_chk(&argvars[0]);
23432350
if (msg != NULL)
23442351
{
23452352
pumitem_T *array;
@@ -2514,6 +2521,8 @@ f_changenr(typval_T *argvars UNUSED, typval_T *rettv)
25142521
static void
25152522
f_char2nr(typval_T *argvars, typval_T *rettv)
25162523
{
2524+
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
2525+
return;
25172526
if (has_mbyte)
25182527
{
25192528
int utf8 = 0;
@@ -2678,11 +2687,16 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
26782687
char_u *typestr;
26792688
int error = FALSE;
26802689

2690+
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
2691+
return;
2692+
26812693
message = tv_get_string_chk(&argvars[0]);
26822694
if (message == NULL)
26832695
error = TRUE;
26842696
if (argvars[1].v_type != VAR_UNKNOWN)
26852697
{
2698+
if (in_vim9script() && check_for_string_arg(argvars, 1) == FAIL)
2699+
return;
26862700
buttons = tv_get_string_buf_chk(&argvars[1], buf);
26872701
if (buttons == NULL)
26882702
error = TRUE;
@@ -2691,6 +2705,8 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
26912705
def = (int)tv_get_number_chk(&argvars[2], &error);
26922706
if (argvars[3].v_type != VAR_UNKNOWN)
26932707
{
2708+
if (in_vim9script() && check_for_string_arg(argvars, 3) == FAIL)
2709+
return;
26942710
typestr = tv_get_string_buf_chk(&argvars[3], buf2);
26952711
if (typestr == NULL)
26962712
error = TRUE;

src/evalvars.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,11 @@ ex_let(exarg_T *eap)
791791
{
792792
if (vim9script)
793793
{
794-
// Vim9 declaration ":var name: type"
795-
arg = vim9_declare_scriptvar(eap, arg);
794+
if (!ends_excmd2(eap->cmd, skipwhite(argend)))
795+
semsg(_(e_trailing_arg), argend);
796+
else
797+
// Vim9 declaration ":var name: type"
798+
arg = vim9_declare_scriptvar(eap, arg);
796799
}
797800
else
798801
{

0 commit comments

Comments
 (0)