ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

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

fix WarnBufferModified logic

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>

Diffstat:
Mbuffer.ha | 15++++-----------
Mcommand.ha | 2+-
Mfile.ha | 1+
3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/buffer.ha b/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 @@ -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 @@ -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);