[vim/vim] ":saveas foo" in a buftype=nofile fails, and with a misleading error (Issue #11171)

39 views
Skip to first unread message

James McCoy

unread,
Sep 19, 2022, 8:28:31 PM9/19/22
to vim/vim, Subscribed

Steps to reproduce

  1. vim --clean
  2. ":set buftype=nofile"
  3. ":saveas foo"
  4. Get "E676: No matching autocommands for acwrite buffer" error, when the buffer is 'nofile', not 'acwrite'

Expected behaviour

It's unclear what should be expected.

“:write foo” is successful in a 'nofile' buffer and that's essentially what “:saveas foo” is doing, from a user perspective. In addition, it also "switches" you to that file. The implementation detail of just renaming the current buffer to the new filename is what seems to lead to this problem.

However, it could also be argued that the command should emit E382 since it's a nofile buffer.

If the use of :saveas is deemed acceptable, it seems like “:saveas foo” should do one of two things:

  1. Act like “:write foo”, “:earlier 1f” (if buffer is modified), “:edit foo”. This preserves whatever buffer-specific options were set on the original buffer, while giving you the file foo with the modifications that have been made.
  2. Move the value of 'buftype' (and possibly other options) to the newly created alternate buffer, which now represents the same "file" the original buffer was displaying, sans the unsaved modifications.

However, 1 would has user visible side effects and is a change in behavior.

2 appears at first blush to be easy to implement, but the trouble is that the alternate buffer isn't loaded until the user switches to it.

Any options set on it before then will be wiped out when it actually gets loaded, last I checked.

Version of Vim

9.1.0242

Environment

Debian

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11171@github.com>

Bram Moolenaar

unread,
Sep 20, 2022, 6:49:53 AM9/20/22
to vim/vim, Subscribed

Closed #11171 as completed via 500a1f9.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11171/issue_event/7421049028@github.com>

Bram Moolenaar

unread,
Sep 20, 2022, 6:50:24 AM9/20/22
to vim/vim, Subscribed


> ### Steps to reproduce
>
> 1. vim --clean
> 2. ":set buftype=nofile"
> 3. ":saveas foo"
> 4. Get "E676: No matching autocommands for acwrite buffer" error, when the buffer is 'nofile', not 'acwrite'
>
> ### Expected behaviour
>
> It's unclear what _should_ be expected.

>
> “:write foo” is successful in a 'nofile' buffer and that's essentially
> what “:saveas foo” is doing, from a user perspective. In addition, it
> also "switches" you to that file. The implementation detail of just
> renaming the current buffer to the new filename is what seems to lead
> to this problem.
>
> However, it could also be argued that the command should emit E382
> since it's a nofile buffer.

Yes, this still uses the same buffer, with all the option settings and
everything. What you are thinking of is ":write foo | edit foo". That
is different, as it creates a new buffer.


> If the use of :saveas is deemed acceptable, it seems like “:saveas
> foo” should do one of two things:
>
> 1. Act like “:write foo”, “:earlier 1f” (if buffer is modified),

> “:edit foo”. This preserves whatever buffer-specific options were set
> on the original buffer, while giving you the file foo with the
> modifications that have been made.

That is not what "saveas" is intended to do, it is intended to keep the
same buffer. When using a different buffer in some cases that gets
confusing.

> 2. Move the value of 'buftype' (and possibly other options) to the

> newly created alternate buffer, which now represents the same "file"
> the original buffer was displaying, sans the unsaved modifications.
>
> However, 1 would has user visible side effects and is a change in
> behavior.

And probably has other side effects.


> 2 appears at first blush to be easy to implement, but the trouble is
> that the alternate buffer isn't loaded until the user switches to it.
>
> Any options set on it before then will be wiped out when it actually
> gets loaded, last I checked.

I think we should just fix the error message.

--
Contrary to popular belief, Unix is user friendly.
It just happens to be selective about who it makes friends with.
-- Dave Parnas

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11171/1252176560@github.com>

Reply all
Reply to author
Forward
0 new messages