Skip to content

Commit c312b8b

Browse files
committed
patch 8.0.1231: expanding file name drops dash
Problem: Expanding file name drops dash. (stucki) Solution: Use the right position. (Christian Brabandt, closes #2184)
1 parent ce15775 commit c312b8b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/ex_docmd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10715,9 +10715,12 @@ eval_vars(
1071510715
if (*s == '<') /* "#<99" uses v:oldfiles */
1071610716
++s;
1071710717
i = (int)getdigits(&s);
10718+
if (s == src + 2 && src[1] == '-')
10719+
/* just a minus sign, don't skip over it */
10720+
s--;
1071810721
*usedlen = (int)(s - src); /* length of what we expand */
1071910722

10720-
if (src[1] == '<')
10723+
if (src[1] == '<' && i != 0)
1072110724
{
1072210725
if (*usedlen < 2)
1072310726
{
@@ -10740,6 +10743,8 @@ eval_vars(
1074010743
}
1074110744
else
1074210745
{
10746+
if (i == 0 && src[1] == '<' && *usedlen > 1)
10747+
*usedlen = 1;
1074310748
buf = buflist_findnr(i);
1074410749
if (buf == NULL)
1074510750
{

src/testdir/test_cmdline.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ func Test_cmdline_complete_user_cmd()
365365
delcommand Foo
366366
endfunc
367367

368+
func Test_cmdline_write_alternatefile()
369+
new
370+
call setline('.', ['one', 'two'])
371+
f foo.txt
372+
new
373+
f #-A
374+
call assert_equal('foo.txt-A', expand('%'))
375+
f #<-B.txt
376+
call assert_equal('foo-B.txt', expand('%'))
377+
f %<
378+
call assert_equal('foo-B', expand('%'))
379+
new
380+
call assert_fails('f #<', 'E95')
381+
bw!
382+
f foo-B.txt
383+
f %<-A
384+
call assert_equal('foo-B-A', expand('%'))
385+
bw!
386+
bw!
387+
endfunc
388+
368389
" using a leading backslash here
369390
set cpo+=C
370391

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1231,
764766
/**/
765767
1230,
766768
/**/

0 commit comments

Comments
 (0)