~torresjrjr/public-inbox

ed: add wq command v2 PROPOSED

Curtis Arthaud: 1
 add wq command

 2 files changed, 24 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~torresjrjr/public-inbox/patches/50241/mbox | git am -3
Learn more about email & git

[PATCH ed v2] add wq command Export this patch

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)?;
};

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;

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.