Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
This should work.
The issue I mentioned earlier is still there,
but is not relevant to this patch
(it also happens with a standalone q)
so I will try to address it separately.
command.ha | 3 +++
parse.ha | 22 +++++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/command.ha b/command.ha
index c20b678..f823d7c 100644
--- a/command.ha
+++ b/command.ha
@@ -737,6 +737,9 @@ fn cmd_write(s: *Session, cmd: *Command) (void | Error) = {
if (a == 1 && b == len(s.buf.lines))
// the entier buffer has been written.
s.buf.modified = false;
+
+ if (cmd.suffix == 'q')
+ cmd_quit(s, cmd)?;
As I mentioned in my earlier late reply, I'd rather the Quit code be
present here, duplicated if necessary, instead of cmd_quit() being
called here.
};
fn cmd_linenumber(s: *Session, cmd: *Command) (void | Error) = {
diff --git a/parse.ha b/parse.ha
index 31925a2..65367c3 100644
--- 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;
+
Nice.
The Hare compiler isn't yet powerful enough to detect this, but this
also needs its own entry in strerror() in <main.ha>.
Entering 'wx<Enter>' will cause a crash.
type UnexpectedSuffix = !rune;
type TrailingCharacters = !void;
@@ -149,7 +152,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 =>
@@ -160,6 +163,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)) {
--
2.44.0
Looking good.