vim-patch:8.0.1231: expanding file name drops dash

Problem:    Expanding file name drops dash. (stucki)
Solution:   Use the right position. (Christian Brabandt, closes vim/vim#2184)
c312b8b87a
This commit is contained in:
Jan Edmund Lazo
2018-08-16 11:03:12 -04:00
parent 6531b175ad
commit be552c8340
2 changed files with 29 additions and 1 deletions

View File

@@ -8521,9 +8521,13 @@ eval_vars (
if (*s == '<') /* "#<99" uses v:oldfiles */ if (*s == '<') /* "#<99" uses v:oldfiles */
++s; ++s;
i = getdigits_int(&s); i = getdigits_int(&s);
if (s == src + 2 && src[1] == '-') {
// just a minus sign, don't skip over it
s--;
}
*usedlen = (size_t)(s - src); /* length of what we expand */ *usedlen = (size_t)(s - src); /* length of what we expand */
if (src[1] == '<') { if (src[1] == '<' && i != 0) {
if (*usedlen < 2) { if (*usedlen < 2) {
/* Should we give an error message for #<text? */ /* Should we give an error message for #<text? */
*usedlen = 1; *usedlen = 1;
@@ -8536,6 +8540,9 @@ eval_vars (
return NULL; return NULL;
} }
} else { } else {
if (i == 0 && src[1] == '<' && *usedlen > 1) {
*usedlen = 1;
}
buf = buflist_findnr(i); buf = buflist_findnr(i);
if (buf == NULL) { if (buf == NULL) {
*errormsg = (char_u *)_( *errormsg = (char_u *)_(

View File

@@ -380,6 +380,27 @@ func Test_cmdline_complete_user_cmd()
delcommand Foo delcommand Foo
endfunc endfunc
func Test_cmdline_write_alternatefile()
new
call setline('.', ['one', 'two'])
f foo.txt
new
f #-A
call assert_equal('foo.txt-A', expand('%'))
f #<-B.txt
call assert_equal('foo-B.txt', expand('%'))
f %<
call assert_equal('foo-B', expand('%'))
new
call assert_fails('f #<', 'E95')
bw!
f foo-B.txt
f %<-A
call assert_equal('foo-B-A', expand('%'))
bw!
bw!
endfunc
" using a leading backslash here " using a leading backslash here
set cpo+=C set cpo+=C