Patch 8.2.2228
Problem: Vim9: cannot use ":e #" because # starts a comment.
Solution: Support using %% instead of #.
Files: src/ex_docmd.c, src/testdir/test_vim9_cmd.vim
*** ../vim-8.2.2227/src/ex_docmd.c 2020-12-26 15:39:24.619550795 +0100
--- src/ex_docmd.c 2020-12-27 16:53:46.569379246 +0100
***************
*** 8535,8552 ****
/*
* Evaluate cmdline variables.
*
! * change '%' to curbuf->b_ffname
! * '#' to curwin->w_alt_fnum
! * '<cword>' to word under the cursor
! * '<cWORD>' to WORD under the cursor
! * '<cexpr>' to C-expression under the cursor
! * '<cfile>' to path name under the cursor
! * '<sfile>' to sourced file name
! * '<stack>' to call stack
! * '<slnum>' to sourced file line number
! * '<afile>' to file name for autocommand
! * '<abuf>' to buffer number for autocommand
! * '<amatch>' to matching name for autocommand
*
* When an error is detected, "errormsg" is set to a non-NULL pointer (may be
* "" for error without a message) and NULL is returned.
--- 8535,8553 ----
/*
* Evaluate cmdline variables.
*
! * change "%" to curbuf->b_ffname
! * "#" to curwin->w_alt_fnum
! * "%%" to curwin->w_alt_fnum in Vim9 script
! * "<cword>" to word under the cursor
! * "<cWORD>" to WORD under the cursor
! * "<cexpr>" to C-expression under the cursor
! * "<cfile>" to path name under the cursor
! * "<sfile>" to sourced file name
! * "<stack>" to call stack
! * "<slnum>" to sourced file line number
! * "<afile>" to file name for autocommand
! * "<abuf>" to buffer number for autocommand
! * "<amatch>" to matching name for autocommand
*
* When an error is detected, "errormsg" is set to a non-NULL pointer (may be
* "" for error without a message) and NULL is returned.
***************
*** 8627,8673 ****
*/
else
{
switch (spec_idx)
{
! case SPEC_PERC: // '%': current file
! if (curbuf->b_fname == NULL)
{
! result = (char_u *)"";
! valid = 0; // Must have ":p:h" to be valid
! }
! else
! {
! result = curbuf->b_fname;
! tilde_file = STRCMP(result, "~") == 0;
}
! break;
case SPEC_HASH: // '#' or "#99": alternate file
! if (src[1] == '#') // "##": the argument list
{
result = arg_all();
resultbuf = result;
! *usedlen = 2;
if (escaped != NULL)
*escaped = TRUE;
skip_mod = TRUE;
break;
}
! s = src + 1;
if (*s == '<') // "#<99" uses v:oldfiles
++s;
i = (int)getdigits(&s);
! if (s == src + 2 && src[1] == '-')
// just a minus sign, don't skip over it
s--;
*usedlen = (int)(s - src); // length of what we expand
! if (src[1] == '<' && i != 0)
{
! if (*usedlen < 2)
{
// Should we give an error message for #<text?
! *usedlen = 1;
return NULL;
}
#ifdef FEAT_EVAL
--- 8628,8684 ----
*/
else
{
+ int off = 0;
+
switch (spec_idx)
{
! case SPEC_PERC:
! if (!in_vim9script() || src[1] != '%')
{
! // '%': current file
! if (curbuf->b_fname == NULL)
! {
! result = (char_u *)"";
! valid = 0; // Must have ":p:h" to be valid
! }
! else
! {
! result = curbuf->b_fname;
! tilde_file = STRCMP(result, "~") == 0;
! }
! break;
}
! // "%%" alternate file
! off = 1;
! // FALLTHROUGH
case SPEC_HASH: // '#' or "#99": alternate file
! if (off == 0 ? src[1] == '#' : src[2] == '%')
{
+ // "##" or "%%%": the argument list
result = arg_all();
resultbuf = result;
! *usedlen = off + 2;
if (escaped != NULL)
*escaped = TRUE;
skip_mod = TRUE;
break;
}
! s = src + off + 1;
if (*s == '<') // "#<99" uses v:oldfiles
++s;
i = (int)getdigits(&s);
! if (s == src + off + 2 && src[off + 1] == '-')
// just a minus sign, don't skip over it
s--;
*usedlen = (int)(s - src); // length of what we expand
! if (src[off + 1] == '<' && i != 0)
{
! if (*usedlen < off + 2)
{
// Should we give an error message for #<text?
! *usedlen = off + 1;
return NULL;
}
#ifdef FEAT_EVAL
***************
*** 8685,8692 ****
}
else
{
! if (i == 0 && src[1] == '<' && *usedlen > 1)
! *usedlen = 1;
buf = buflist_findnr(i);
if (buf == NULL)
{
--- 8696,8703 ----
}
else
{
! if (i == 0 && src[off + 1] == '<' && *usedlen > off + 1)
! *usedlen = off + 1;
buf = buflist_findnr(i);
if (buf == NULL)
{
*** ../vim-8.2.2227/src/testdir/test_vim9_cmd.vim 2020-12-25
19:47:21.581534942 +0100
--- src/testdir/test_vim9_cmd.vim 2020-12-27 16:46:30.559040727 +0100
***************
*** 25,30 ****
--- 25,77 ----
CheckDefFailure(['edit `="foo"'], 'E1083:')
enddef
+ def Test_expand_alternate_file()
+ var lines =<< trim END
+ edit Xfileone
+ var bone = bufnr()
+ edit Xfiletwo
+ var btwo = bufnr()
+ edit Xfilethree
+ var bthree = bufnr()
+
+ edit #
+ assert_equal(bthree, bufnr())
+ edit %%
+ assert_equal(btwo, bufnr())
+ edit %% # comment
+ assert_equal(bthree, bufnr())
+ edit %%yy
+ assert_equal('Xfiletwoyy', bufname())
+
+ exe "edit %%" .. bone
+ assert_equal(bone, bufnr())
+ exe "edit %%" .. btwo .. "xx"
+ assert_equal('Xfiletwoxx', bufname())
+
+ next Xfileone Xfiletwo Xfilethree
+ assert_equal('Xfileone', argv(0))
+ assert_equal('Xfiletwo', argv(1))
+ assert_equal('Xfilethree', argv(2))
+ next %%%zz
+ assert_equal('Xfileone', argv(0))
+ assert_equal('Xfiletwo', argv(1))
+ assert_equal('Xfilethreezz', argv(2))
+
+ v:oldfiles = ['Xonefile', 'Xtwofile']
+ edit %%<1
+ assert_equal('Xonefile', bufname())
+ edit %%<2
+ assert_equal('Xtwofile', bufname())
+ assert_fails('edit %%<3', 'E684:')
+
+ edit Xfileone.vim
+ edit Xfiletwo
+ edit %%:r
+ assert_equal('Xfileone', bufname())
+ END
+ CheckDefAndScriptSuccess(lines)
+ enddef
+
def Test_global_backtick_expansion()
new
setline(1, 'xx')
*** ../vim-8.2.2227/src/version.c 2020-12-27 14:43:23.497570151 +0100
--- src/version.c 2020-12-27 15:59:52.770527843 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2228,
/**/
--
"You know, it's at times like this when I'm trapped in a Vogon airlock with
a man from Betelgeuse and about to die of asphyxiation in deep space that I
really wish I'd listened to what my mother told me when I was young!"
"Why, what did she tell you?"
"I don't know, I didn't listen!"
-- Arthur Dent and Ford Prefect in Douglas Adams'
"The Hitchhiker's Guide to the Galaxy"
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202012271555.0BRFtbap4162862%40masaka.moolenaar.net.