ed

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

commit 8f93b0969ad7ec232543cddd0d9830072bc66836
parent 3257635eedc132400da16934708d94f7bf966f32
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed, 17 Jan 2024 22:00:59 +0000

discard hist of no-op commands

Diffstat:
Mcommand.ha | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/command.ha b/command.ha @@ -121,7 +121,9 @@ fn cmd_append(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum(cmd.linenums, s.buf.cursor); - hist_newseq(s.buf); // TODO: special case, len(cmd.textinput) == 0 + if (len(cmd.textinput) > 0) + hist_newseq(s.buf); + for (let i = 0z; i < len(cmd.textinput); i += 1) { const line = alloc(Line{ text = cmd.textinput[i], ... }); buf_insert(s.buf, n + 1 + i, line); @@ -462,9 +464,13 @@ fn cmd_read(s: *Session, cmd: *Command) (void | Error) = { }; defer io::close(rd)!; - hist_newseq(s.buf); // TODO: special case, zero input + hist_newseq(s.buf); + const (sz, _) = buf_read(s.buf, rd, n)?; + if (sz == 0) + hist_discardseq(s.buf); + if (!s.suppressmode) fmt::println(sz)!; @@ -492,7 +498,8 @@ fn cmd_substitute(s: *Session, cmd: *Command) (void | Error) = { let changes = 0z; - hist_newseq(s.buf); // TODO: special case, no match or changes + hist_newseq(s.buf); + for (let n = a; n <= b; n += 1) { const old = s.buf.lines[n].text; const results = regex::findall(&re, old); @@ -537,8 +544,10 @@ fn cmd_substitute(s: *Session, cmd: *Command) (void | Error) = { changes += 1; }; - if (changes == 0) + if (changes == 0) { + hist_discardseq(s.buf); return NoMatch; + }; printmode(s, cmd)?; };