Skip to content

Commit 0692eb5

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 7c9b86b + 7a3330f commit 0692eb5

34 files changed

Lines changed: 699 additions & 208 deletions

runtime/doc/eval.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,8 @@ str2list({expr} [, {utf8}]) List convert each character of {expr} to
28482848
str2nr({expr} [, {base} [, {quoted}]])
28492849
Number convert String to Number
28502850
strcharpart({str}, {start} [, {len}])
2851-
String {len} characters of {str} at {start}
2851+
String {len} characters of {str} at
2852+
character {start}
28522853
strchars({expr} [, {skipcc}]) Number character length of the String {expr}
28532854
strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
28542855
strftime({format} [, {time}]) String format time with a specified format
@@ -2857,8 +2858,9 @@ stridx({haystack}, {needle} [, {start}])
28572858
Number index of {needle} in {haystack}
28582859
string({expr}) String String representation of {expr} value
28592860
strlen({expr}) Number length of the String {expr}
2860-
strpart({str}, {start} [, {len}])
2861-
String {len} bytes of {str} at byte {start}
2861+
strpart({str}, {start} [, {len} [, {chars}]])
2862+
String {len} bytes/chars of {str} at
2863+
byte {start}
28622864
strptime({format}, {timestring})
28632865
Number Convert {timestring} to unix timestamp
28642866
strridx({haystack}, {needle} [, {start}])
@@ -3430,7 +3432,8 @@ byte2line({byte}) *byte2line()*
34303432

34313433
byteidx({expr}, {nr}) *byteidx()*
34323434
Return byte index of the {nr}'th character in the string
3433-
{expr}. Use zero for the first character, it returns zero.
3435+
{expr}. Use zero for the first character, it then returns
3436+
zero.
34343437
This function is only useful when there are multibyte
34353438
characters, otherwise the returned value is equal to {nr}.
34363439
Composing characters are not counted separately, their byte
@@ -9960,17 +9963,22 @@ strlen({expr}) The result is a Number, which is the length of the String
99609963
{expr} in bytes.
99619964
If the argument is a Number it is first converted to a String.
99629965
For other types an error is given.
9963-
If you want to count the number of multi-byte characters use
9966+
If you want to count the number of multibyte characters use
99649967
|strchars()|.
99659968
Also see |len()|, |strdisplaywidth()| and |strwidth()|.
99669969

99679970
Can also be used as a |method|: >
99689971
GetString()->strlen()
99699972

9970-
strpart({src}, {start} [, {len}]) *strpart()*
9973+
strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
99719974
The result is a String, which is part of {src}, starting from
99729975
byte {start}, with the byte length {len}.
9973-
To count characters instead of bytes use |strcharpart()|.
9976+
When {chars} is present and TRUE then {len} is the number of
9977+
characters positions (composing characters are not counted
9978+
separately, thus "1" means one base character and any
9979+
following composing characters).
9980+
To count {start} as characters instead of bytes use
9981+
|strcharpart()|.
99749982

99759983
When bytes are selected which do not exist, this doesn't
99769984
result in an error, the bytes are simply omitted.
@@ -9982,8 +9990,8 @@ strpart({src}, {start} [, {len}]) *strpart()*
99829990
strpart("abcdefg", 3) == "defg"
99839991

99849992
< Note: To get the first character, {start} must be 0. For
9985-
example, to get three bytes under and after the cursor: >
9986-
strpart(getline("."), col(".") - 1, 3)
9993+
example, to get the character under the cursor: >
9994+
strpart(getline("."), col(".") - 1, 1, v:true)
99879995
<
99889996
Can also be used as a |method|: >
99899997
GetText()->strpart(5)

src/channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ channel_connect(
923923
*waittime -= elapsed_msec;
924924
if (waitnow > 0)
925925
{
926-
mch_delay((long)waitnow, TRUE);
926+
mch_delay((long)waitnow, MCH_DELAY_IGNOREINPUT);
927927
ui_breakcheck();
928928
*waittime -= waitnow;
929929
}

src/eval.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
26752675
int oplen;
26762676
int concat;
26772677
typval_T var2;
2678+
int vim9script = in_vim9script();
26782679

26792680
// "." is only string concatenation when scriptversion is 1
26802681
p = eval_next_non_blank(*arg, evalarg, &getnext);
@@ -2689,7 +2690,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
26892690
*arg = eval_next_line(evalarg);
26902691
else
26912692
{
2692-
if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
2693+
if (evaluate && vim9script && !VIM_ISWHITE(**arg))
26932694
{
26942695
error_white_both(p, oplen);
26952696
clear_tv(rettv);
@@ -2721,14 +2722,14 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
27212722
/*
27222723
* Get the second variable.
27232724
*/
2724-
if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen]))
2725+
if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[oplen]))
27252726
{
27262727
error_white_both(p, oplen);
27272728
clear_tv(rettv);
27282729
return FAIL;
27292730
}
27302731
*arg = skipwhite_and_linebreak(*arg + oplen, evalarg);
2731-
if (eval6(arg, &var2, evalarg, !in_vim9script() && op == '.') == FAIL)
2732+
if (eval6(arg, &var2, evalarg, !vim9script && op == '.') == FAIL)
27322733
{
27332734
clear_tv(rettv);
27342735
return FAIL;
@@ -2745,12 +2746,12 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
27452746
char_u *s1 = tv_get_string_buf(rettv, buf1);
27462747
char_u *s2 = NULL;
27472748

2748-
if (in_vim9script() && (var2.v_type == VAR_VOID
2749+
if (vim9script && (var2.v_type == VAR_VOID
27492750
|| var2.v_type == VAR_CHANNEL
27502751
|| var2.v_type == VAR_JOB))
27512752
emsg(_(e_inval_string));
27522753
#ifdef FEAT_FLOAT
2753-
else if (var2.v_type == VAR_FLOAT)
2754+
else if (vim9script && var2.v_type == VAR_FLOAT)
27542755
{
27552756
vim_snprintf((char *)buf2, NUMBUFLEN, "%g",
27562757
var2.vval.v_float);

src/evalfunc.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ static funcentry_T global_functions[] =
950950
{"stridx", 2, 3, FEARG_1, ret_number, f_stridx},
951951
{"string", 1, 1, FEARG_1, ret_string, f_string},
952952
{"strlen", 1, 1, FEARG_1, ret_number, f_strlen},
953-
{"strpart", 2, 3, FEARG_1, ret_string, f_strpart},
953+
{"strpart", 2, 4, FEARG_1, ret_string, f_strpart},
954954
{"strptime", 2, 2, FEARG_1, ret_number,
955955
#ifdef HAVE_STRPTIME
956956
f_strptime
@@ -8305,10 +8305,8 @@ f_strpart(typval_T *argvars, typval_T *rettv)
83058305
else
83068306
len = slen - n; // default len: all bytes that are available.
83078307

8308-
/*
8309-
* Only return the overlap between the specified part and the actual
8310-
* string.
8311-
*/
8308+
// Only return the overlap between the specified part and the actual
8309+
// string.
83128310
if (n < 0)
83138311
{
83148312
len += n;
@@ -8321,6 +8319,16 @@ f_strpart(typval_T *argvars, typval_T *rettv)
83218319
else if (n + len > slen)
83228320
len = slen - n;
83238321

8322+
if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN)
8323+
{
8324+
int off;
8325+
8326+
// length in characters
8327+
for (off = n; off < slen && len > 0; --len)
8328+
off += mb_ptr2len(p + off);
8329+
len = off - n;
8330+
}
8331+
83248332
rettv->v_type = VAR_STRING;
83258333
rettv->vval.v_string = vim_strnsave(p + n, len);
83268334
}

src/evalvars.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,20 @@ eval_variable(
24632463
tv = sv->sv_tv;
24642464
}
24652465
}
2466+
else if (in_vim9script())
2467+
{
2468+
ufunc_T *ufunc = find_func(name, FALSE, NULL);
2469+
2470+
if (ufunc != NULL)
2471+
{
2472+
foundFunc = TRUE;
2473+
if (rettv != NULL)
2474+
{
2475+
rettv->v_type = VAR_FUNC;
2476+
rettv->vval.v_string = vim_strsave(ufunc->uf_name);
2477+
}
2478+
}
2479+
}
24662480
}
24672481

24682482
if (!foundFunc)

0 commit comments

Comments
 (0)