Skip to content

Commit 0fa638f

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 38d2ba8 + dfc3db7 commit 0fa638f

50 files changed

Lines changed: 857 additions & 99 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

runtime/doc/eval.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,8 @@ finddir({name} [, {path} [, {count}]])
25612561
findfile({name} [, {path} [, {count}]])
25622562
String find file {name} in {path}
25632563
flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
2564+
flattennew({list} [, {maxdepth}])
2565+
List flatten a copy of {list}
25642566
float2nr({expr}) Number convert Float {expr} to a Number
25652567
floor({expr}) Float round {expr} down
25662568
fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
@@ -2572,6 +2574,7 @@ foldlevel({lnum}) Number fold level at {lnum}
25722574
foldtext() String line displayed for closed fold
25732575
foldtextresult({lnum}) String text for closed fold at {lnum}
25742576
foreground() Number bring the Vim window to the foreground
2577+
fullcommand({name}) String get full command from {name}
25752578
funcref({name} [, {arglist}] [, {dict}])
25762579
Funcref reference to function {name}
25772580
function({name} [, {arglist}] [, {dict}])
@@ -4724,8 +4727,10 @@ flatten({list} [, {maxdepth}]) *flatten()*
47244727
Flatten {list} up to {maxdepth} levels. Without {maxdepth}
47254728
the result is a |List| without nesting, as if {maxdepth} is
47264729
a very large number.
4727-
The {list} is changed in place, make a copy first if you do
4730+
The {list} is changed in place, use |flattennew()| if you do
47284731
not want that.
4732+
In Vim9 script flatten() cannot be used, you must always use
4733+
|flattennew()|.
47294734
*E900*
47304735
{maxdepth} means how deep in nested lists changes are made.
47314736
{list} is not modified when {maxdepth} is 0.
@@ -4739,6 +4744,10 @@ flatten({list} [, {maxdepth}]) *flatten()*
47394744
:echo flatten([1, [2, [3, 4]], 5], 1)
47404745
< [1, 2, [3, 4], 5]
47414746

4747+
flattennew({list} [, {maxdepth}]) *flattennew()*
4748+
Like |flatten()| but first make a copy of {list}.
4749+
4750+
47424751
float2nr({expr}) *float2nr()*
47434752
Convert {expr} to a Number by omitting the part after the
47444753
decimal point.
@@ -4906,6 +4915,21 @@ foreground() Move the Vim window to the foreground. Useful when sent from
49064915
{only in the Win32, Athena, Motif and GTK GUI versions and the
49074916
Win32 console version}
49084917

4918+
fullcommand({name}) *fullcommand()*
4919+
Get the full command name from a short abbreviated command
4920+
name; see |20.2| for details on command abbreviations.
4921+
4922+
{name} may start with a `:` and can include a [range], these
4923+
are skipped and not returned.
4924+
Returns an empty string if a command doesn't exist or if it's
4925+
ambiguous (for user-defined functions).
4926+
4927+
For example `fullcommand('s')`, `fullcommand('sub')`,
4928+
`fullcommand(':%substitute')` all return "substitute".
4929+
4930+
Can also be used as a |method|: >
4931+
GetName()->fullcommand()
4932+
<
49094933
*funcref()*
49104934
funcref({name} [, {arglist}] [, {dict}])
49114935
Just like |function()|, but the returned Funcref will lookup

runtime/doc/options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4969,6 +4969,10 @@ A jump table for the options with a short description can be found at |Q_op|.
49694969
*lcs-space*
49704970
space:c Character to show for a space. When omitted, spaces
49714971
are left blank.
4972+
*lcs-lead*
4973+
lead:c Character to show for leading spaces. When omitted,
4974+
leading spaces are blank. Overrides the "space"
4975+
setting for leading spaces.
49724976
*lcs-trail*
49734977
trail:c Character to show for trailing spaces. When omitted,
49744978
trailing spaces are blank. Overrides the "space"

runtime/doc/usr_41.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ List manipulation: *list-functions*
665665
count() count number of times a value appears in a List
666666
repeat() repeat a List multiple times
667667
flatten() flatten a List
668+
flattennew() flatten a copy of a List
668669

669670
Dictionary manipulation: *dict-functions*
670671
get() get an entry without an error for a wrong key
@@ -882,6 +883,7 @@ Command line: *command-line-functions*
882883
getcmdtype() return the current command-line type
883884
getcmdwintype() return the current command-line window type
884885
getcompletion() list of command-line completion matches
886+
fullcommand() get full command name
885887

886888
Quickfix and location lists: *quickfix-functions*
887889
getqflist() list of quickfix errors

runtime/doc/vim9.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ In case the key needs to be an expression, square brackets can be used, just
548548
like in JavaScript: >
549549
var dict = {["key" .. nr]: value}
550550
551+
The key type can be string, number, bool or float. Other types result in an
552+
error. A number can be given with and without the []: >
553+
var dict = {123: 'without', [456]: 'with'}
554+
echo dict
555+
{'456': 'with', '123': 'without'}
556+
551557
552558
No :xit, :t, :append, :change or :insert ~
553559

src/arglist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ ex_args(exarg_T *eap)
557557

558558
if (eap->cmdidx != CMD_args)
559559
{
560+
if (check_arglist_locked() == FAIL)
561+
return;
560562
alist_unlink(ALIST(curwin));
561563
if (eap->cmdidx == CMD_argglobal)
562564
ALIST(curwin) = &global_alist;
@@ -566,6 +568,8 @@ ex_args(exarg_T *eap)
566568

567569
if (*eap->arg != NUL)
568570
{
571+
if (check_arglist_locked() == FAIL)
572+
return;
569573
// ":args file ..": define new argument list, handle like ":next"
570574
// Also for ":argslocal file .." and ":argsglobal file ..".
571575
ex_next(eap);

src/bufwrite.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,9 @@ buf_write(
14961496
#endif
14971497
#if defined(HAVE_SELINUX) || defined(HAVE_SMACK)
14981498
mch_copy_sec(fname, backup);
1499+
#endif
1500+
#ifdef MSWIN
1501+
(void)mch_copy_file_attribute(fname, backup);
14991502
#endif
15001503
break;
15011504
}
@@ -1909,12 +1912,7 @@ buf_write(
19091912

19101913
#if defined(MSWIN)
19111914
if (backup != NULL && overwriting && !append)
1912-
{
1913-
if (backup_copy)
1914-
(void)mch_copy_file_attribute(wfname, backup);
1915-
else
1916-
(void)mch_copy_file_attribute(backup, wfname);
1917-
}
1915+
(void)mch_copy_file_attribute(backup, wfname);
19181916

19191917
if (!overwriting && !append)
19201918
{

src/dict.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,13 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
953953
}
954954
if (evaluate)
955955
{
956-
if (vim9script && check_for_string(&tvkey) == FAIL)
956+
#ifdef FEAT_FLOAT
957+
if (tvkey.v_type == VAR_FLOAT)
957958
{
958-
clear_tv(&tvkey);
959-
goto failret;
959+
tvkey.vval.v_string = typval_tostring(&tvkey, TRUE);
960+
tvkey.v_type = VAR_STRING;
960961
}
962+
#endif
961963
key = tv_get_string_buf_chk(&tvkey, buf);
962964
if (key == NULL)
963965
{

src/drawline.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ win_line(
339339
int change_end = -1; // last col of changed area
340340
#endif
341341
colnr_T trailcol = MAXCOL; // start of trailing spaces
342+
colnr_T leadcol = 0; // start of leading spaces
342343
#ifdef FEAT_LINEBREAK
343344
int need_showbreak = FALSE; // overlong line, skipping first x
344345
// chars
@@ -734,8 +735,9 @@ win_line(
734735

735736
if (wp->w_p_list)
736737
{
737-
if (lcs_space || lcs_trail || lcs_nbsp)
738+
if (lcs_space || lcs_trail || lcs_lead || lcs_nbsp)
738739
extra_check = TRUE;
740+
739741
// find start of trailing whitespace
740742
if (lcs_trail)
741743
{
@@ -744,6 +746,19 @@ win_line(
744746
--trailcol;
745747
trailcol += (colnr_T) (ptr - line);
746748
}
749+
// find end of leading whitespace
750+
if (lcs_lead)
751+
{
752+
leadcol = 0;
753+
while (VIM_ISWHITE(ptr[leadcol]))
754+
++leadcol;
755+
if (ptr[leadcol] == NUL)
756+
// in a line full of spaces all of them are treated as trailing
757+
leadcol = (colnr_T)0;
758+
else
759+
// keep track of the first column not filled with spaces
760+
leadcol += (colnr_T) (ptr - line) + 1;
761+
}
747762
}
748763

749764
wcr_attr = get_wcr_attr(wp);
@@ -1992,6 +2007,7 @@ win_line(
19922007
|| (c == ' '
19932008
&& mb_l == 1
19942009
&& lcs_space
2010+
&& ptr - line >= leadcol
19952011
&& ptr - line <= trailcol)))
19962012
{
19972013
c = (c == ' ') ? lcs_space : lcs_nbsp;
@@ -2012,9 +2028,10 @@ win_line(
20122028
mb_utf8 = FALSE;
20132029
}
20142030

2015-
if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2031+
if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2032+
|| (leadcol != 0 && ptr < line + leadcol && c == ' '))
20162033
{
2017-
c = lcs_trail;
2034+
c = (ptr > line + trailcol) ? lcs_trail : lcs_lead;
20182035
if (!attr_pri)
20192036
{
20202037
n_attr = 1;

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,5 @@ EXTERN char e_cannot_change_arglist_recursively[]
351351
INIT(= N_("E1156: Cannot change the argument list recursively"));
352352
EXTERN char e_missing_return_type[]
353353
INIT(= N_("E1157: Missing return type"));
354+
EXTERN char e_cannot_use_flatten_in_vim9_script[]
355+
INIT(= N_("E1158: Cannot use flatten() in Vim9 script"));

src/eval.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,11 +3849,23 @@ eval_index(
38493849
clear_tv(&var1);
38503850
return FAIL;
38513851
}
3852-
else if (evaluate && tv_get_string_chk(&var1) == NULL)
3852+
else if (evaluate)
38533853
{
3854-
// not a number or string
3855-
clear_tv(&var1);
3856-
return FAIL;
3854+
#ifdef FEAT_FLOAT
3855+
// allow for indexing with float
3856+
if (vim9 && rettv->v_type == VAR_DICT
3857+
&& var1.v_type == VAR_FLOAT)
3858+
{
3859+
var1.vval.v_string = typval_tostring(&var1, TRUE);
3860+
var1.v_type = VAR_STRING;
3861+
}
3862+
#endif
3863+
if (tv_get_string_chk(&var1) == NULL)
3864+
{
3865+
// not a number or string
3866+
clear_tv(&var1);
3867+
return FAIL;
3868+
}
38573869
}
38583870

38593871
/*
@@ -4065,8 +4077,6 @@ eval_index_inner(
40654077
n2 = len + n2;
40664078
else if (n2 >= len)
40674079
n2 = len;
4068-
if (exclusive)
4069-
--n2;
40704080
if (n1 >= len || n2 < 0 || n1 > n2)
40714081
s = NULL;
40724082
else

0 commit comments

Comments
 (0)