~torresjrjr/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH ed v3] fix buffermodified logic

Curtis Arthaud <uku82@gmx.fr>
Details
Message ID
<20240317141957.20677-2-uku82@gmx.fr>
DKIM signature
pass
Download raw message
Patch: +6 -12
Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
 buffer.ha  | 15 ++++-----------
 command.ha |  2 +-
 file.ha    |  1 +
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/buffer.ha b/buffer.ha
index 196afa6..a32216f 100644
--- a/buffer.ha
@@ -11,7 +11,6 @@ type Buffer = struct{
	hist: []ChangeSeq,
	cursor: size,
	modified: bool,
	written: bool,
	redolastchange: bool,
};

@@ -34,8 +33,7 @@ fn buf_insert(buf: *Buffer, n: size, ls: *Line...) void = {

	insert(buf.lines[n], ls...);

	if (buf.written)
		buf.modified = true;
	buf.modified = true;

	hist_append(buf, (n, len(ls)): Addition);

@@ -47,8 +45,7 @@ fn buf_deleteall(buf: *Buffer) void = {
		append(buf.trash, buf.lines[1..]...);
		delete(buf.lines[1..]);
	};
	if (buf.written)
		buf.modified = true;
	buf.modified = true;
};

fn buf_delete(buf: *Buffer, a: size, b: size) void = {
@@ -57,8 +54,7 @@ fn buf_delete(buf: *Buffer, a: size, b: size) void = {
	append(buf.trash, buf.lines[a..b+1]...);
	delete(buf.lines[a..b+1]);

	if (buf.written)
		buf.modified = true;
	buf.modified = true;

	hist_append(buf, (a, (b + 1 - a)): Deletion);

@@ -91,8 +87,7 @@ fn buf_read(

	hist_append(buf, (n + 1, m): Addition);

	if (buf.written)
		buf.modified = true;
	buf.modified = true;

	return (sz, m);
};
@@ -102,8 +97,6 @@ fn buf_write(buf: *Buffer, dest: io::handle, a: size, b: size) (size | io::error
	for (let n = a; n <= b; n += 1)
		sz += fmt::fprintln(dest, buf.lines[n].text)?;

	buf.written = true; // TODO: move into cmd_write() ?

	return sz;
};

diff --git a/command.ha b/command.ha
index 544b027..9ba1207 100644
--- a/command.ha
+++ b/command.ha
@@ -667,7 +667,7 @@ fn cmd_write(s: *Session, cmd: *Command) (void | Error) = {
	if (!s.suppressmode)
		fmt::println(sz)!;

	if (a == 1 && b == len(s.buf.lines))
	if (a == 1 && b == len(s.buf.lines)-1)
		// the entire buffer has been written.
		s.buf.modified = false;

diff --git a/file.ha b/file.ha
index e8bab6d..c3068e7 100644
--- a/file.ha
+++ b/file.ha
@@ -20,6 +20,7 @@ fn edit(s: *Session, cmd: *Command, forced: bool) (void | Error) = {

	buf_deleteall(s.buf);
	const (sz, _) = buf_read(s.buf, rd, 0)?;
	s.buf.modified = false;

	hist_discardseq(s.buf);

--
2.44.0
Details
Message ID
<CZW6851IQ9FB.R9VEEMZBR0OA@torresjrjr.com>
In-Reply-To
<20240317141957.20677-2-uku82@gmx.fr> (view parent)
DKIM signature
pass
Download raw message
On Sun Mar 17, 2024 at 2:19 PM GMT, Curtis Arthaud wrote:
> Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
> ---
>  buffer.ha  | 15 ++++-----------
>  command.ha |  2 +-
>  file.ha    |  1 +
>  3 files changed, 6 insertions(+), 12 deletions(-)

Thank you. Applied to master.

commit f946d8069cdbb17baba376dec532e1b11285657e
Author: Curtis Arthaud <uku82@gmx.fr>
Date:   Sun Mar 17 15:19:58 2024 +0100

    fix WarnBufferModified logic

    Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
Reply to thread Export thread (mbox)