ed

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

commit 8ef74c1b55a5c17833ae9dc236145cfa14903d21
parent e54fcfe3d304dbb92ae4dec8cc45d9680bde0c77
Author: Curtis Arthaud <uku82@gmx.fr>
Date:   Sat, 16 Mar 2024 10:24:45 +0100

add wq command

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

Diffstat:
Mcommand.ha | 10+++++++++-
Merror.ha | 2++
Mparse.ha | 22+++++++++++++++++++++-
3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/command.ha b/command.ha @@ -668,8 +668,16 @@ fn cmd_write(s: *Session, cmd: *Command) (void | Error) = { fmt::println(sz)!; if (a == 1 && b == len(s.buf.lines)) - // the entier buffer has been written. + // the entire buffer has been written. s.buf.modified = false; + + if (cmd.suffix == 'q') { + if (s.buf.modified && !s.warned) { + s.warned = true; + return WarnBufferModified; + }; + return Quit; + }; }; fn cmd_linenumber(s: *Session, cmd: *Command) (void | Error) = { diff --git a/error.ha b/error.ha @@ -65,6 +65,8 @@ fn strerror(err: Error) str = { // ParseError case let e: UnknownCommand => return "Unknown command"; // TODO: append 'e'? + case InvalidSuffix => + return "Invalid suffix"; case UnexpectedSuffix => return "Unexpected suffix"; case TrailingCharacters => diff --git a/parse.ha b/parse.ha @@ -7,6 +7,7 @@ use strings; type ParseError = !( UnknownCommand + | InvalidSuffix | UnexpectedSuffix | TrailingCharacters | ExpectedArgument @@ -17,6 +18,8 @@ type ParseError = !( type UnknownCommand = !rune; +type InvalidSuffix = !rune; + type UnexpectedSuffix = !rune; type TrailingCharacters = !void; @@ -143,7 +146,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { return true; // .[ <file>] - case 'e', 'E', 'f', 'r', 'w' => + case 'e', 'E', 'f', 'r' => if (scan_blanks(t) == 0) match (strings::next(t)) { case let r: rune => @@ -154,6 +157,23 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { cmd.arg1 = scan_rest(t); return true; + // w(q|[ <file>]) + case 'w' => + if (scan_blanks(t) == 0) + match (strings::next(t)) { + case let r: rune => + if (r == 'q') { + cmd.suffix = r; + return true; + } else { + return r: InvalidSuffix; + }; + case void => + return true; + }; + cmd.arg1 = scan_rest(t); + return true; + // k<x> case 'k' => match (strings::next(t)) {