~torresjrjr/public-inbox

ed: quit: warn buffer modified after failed e cmd v1 REJECTED

Curtis Arthaud: 1
 quit: warn buffer modified after failed e cmd

 1 files changed, 0 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~torresjrjr/public-inbox/patches/50267/mbox | git am -3
Learn more about email & git

[PATCH ed] quit: warn buffer modified after failed e cmd Export this patch

Before this patch we had:

*a
hello
.
*e another_file
Warning: Buffer modified
*q # happily quits, losing "hello"

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
 file.ha | 1 -
 1 file changed, 1 deletion(-)

diff --git a/file.ha b/file.ha
index c3068e7..6396bbd 100644
--- a/file.ha
+++ b/file.ha
@@ -9,7 +9,6 @@ fn edit(s: *Session, cmd: *Command, forced: bool) (void | Error) = {
	assert_noaddrs(s, cmd.linenums)?;

	if (!forced && s.buf.modified && !s.warned) {
		s.warned = true;
		return WarnBufferModified;
	};

--
2.44.0




It is not super clear whether ['e', 'q'] or ['q', 'e'] counts as
"repeating". I think it is inferred from the first paragraph that it is
the destroying of the editor buffer that is more important than the
command that causes that destruction. GNU ed follows this
interpretation, and I agree with it.

	$ ed --version | head -n1
	GNU ed 1.20.1
	$ ed preexistingfile
	H
	P
	*a
	hello
	.
	*e
	Warning: buffer modified
	*q
	$ ed preexistingfile
	H
	P
	*a
	hello
	.
	*q
	Warning: buffer modified
	*e
	419
	*q
	$ 

Besides, removing that line of code I think isn't correct. You'd have to
implement `Session.warned_edit` and `Session.warned_quit`.