bwipeout "%" fails with E94 in vim9script

34 views
Skip to first unread message

Michael Soyka

unread,
May 13, 2024, 12:55:13 PM5/13/24
to vim_dev
In the process of converting a file from vimscript to vim9script, I came across the following inconsistent behavior with the ex-command bwipeout "%".  I'm running gvim 9.1.136 in Windows 10.  The problem is demonstrated by the two scripts below.

bwipeoutBug.vim:
    " Source this script, then enter the ex-command :call BWO().
    " The "wipeout "%" command succeeds
    "
    edit $VIMRUNTIME/filetype.vim
    function! g:BWO()
        bwipeout "%"
    endfunction

bwipeoutBug9.vim:
    vim9script
    # Source this script, then enter the ex-command :call BWO9().
    # The "wipeout "%" command returns E94: No matching buffer for "%"
    #
    edit $VIMRUNTIME/filetype.vim
    def g:BWO9()
        bwipeout "%"
    enddef


Christian J. Robinson

unread,
May 13, 2024, 1:16:25 PM5/13/24
to vim...@googlegroups.com
Try it without the quotes:

    bwipeout %

--
--
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 vim_dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/4ae54f87-8773-4058-b7be-bd45e30d6682n%40googlegroups.com.


--
Christian J. Robinson <hep...@gmail.com>

Michael Soyka

unread,
May 13, 2024, 2:26:52 PM5/13/24
to vim_dev
Yes, your are right- the bwipeout command succeeds without the double quotes in vim9script.  Thanks for the solution!

Given that, what feature of vim9script causes the error when double quotes are used?  In legacy vimscript, it doesn't matter if double quotes are present or not.  Perhaps this should be added to vim9-differences documentation.

Christian Brabandt

unread,
May 13, 2024, 4:16:05 PM5/13/24
to vim...@googlegroups.com

On Mo, 13 Mai 2024, Michael Soyka wrote:

> Yes, your are right- the bwipeout command succeeds without the double
> quotes in vim9script. Thanks for the solution!
>
> Given that, what feature of vim9script causes the error when double
> quotes are used? In legacy vimscript, it doesn't matter if double
> quotes are present or not. Perhaps this should be added to
> vim9-differences documentation.
[...]
> bwipeout "%"

There is a slight difference here. Remember that `"` is the comment
character in legacy Vim Script, so what Vim actually sees and runs is:

:bwipeout

On Vim9 Script, I think it sees the whole argument "%" and expands to
the current buffer name. So by coincidence it behaves the same, but just
because :bw will wipe the current buffer if no argument has been given.

Thanks,
Chris
--
I feel partially hydrogenated!

Michael Soyka

unread,
May 13, 2024, 10:10:29 PM5/13/24
to vim...@googlegroups.com
Now that I think about it, perhaps the reason ':bwipeout "%"' fails with
error E94 is because "%", with the double quotes, is passed to bwipeout
which understands % as a buffer name but not "%".

I think this explains the behavior.  Thanks for the conversation!

Michael Soyka

unread,
May 13, 2024, 10:10:29 PM5/13/24
to vim...@googlegroups.com
Chris,

Thank you for the explanation but I don't think it explains everything. 
See below.

On 05/13/2024 4:15 PM, Christian Brabandt wrote:
> On Mo, 13 Mai 2024, Michael Soyka wrote:
>
>> Yes, your are right- the bwipeout command succeeds without the double
>> quotes in vim9script. Thanks for the solution!
>>
>> Given that, what feature of vim9script causes the error when double
>> quotes are used? In legacy vimscript, it doesn't matter if double
>> quotes are present or not. Perhaps this should be added to
>> vim9-differences documentation.
> [...]
>> bwipeout "%"
> There is a slight difference here. Remember that `"` is the comment
> character in legacy Vim Script, so what Vim actually sees and runs is:
>
> :bwipeout
Yes, I completely overlooked the end-of-line comment possibility and
your explanation makes perfect sense.  When in doubt, RTFM!
>
> On Vim9 Script, I think it sees the whole argument "%" and expands to
> the current buffer name. So by coincidence it behaves the same, but just
> because :bw will wipe the current buffer if no argument has been given.

Actually, if I disassemble the Vim9-script function (what I should have
done earlier), what I see is :

    EXEC bwipeout "%"

and, if executed according to legacy rules, would be equivalent to 'EXEC
bwipeout' and that should succeed but instead it fails with error E94. 
On the other hand, if it substitutes the buffer name, that should also
succeed but it fails with E94.

>
> Thanks,
> Chris

Tony Mechelynck

unread,
May 14, 2024, 4:01:25 AM5/14/24
to vim...@googlegroups.com
I think (but actually I don't write Vim9 scripts myself yet so this is
pure untested theory) that at this point Vim, under Vim9 rules, looks
for a buffer actually named "%" with two double-quotes and a
percent-sign between them, i.e. the equivalent of something like
(IIUC)

:legacy bwipeout \"\%\"

…and of course it doesn't find it.

Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages