~torresjrjr/public-inbox

ed: add wq command v4 APPLIED

Curtis Arthaud: 1
 add wq command

 3 files changed, 32 insertions(+), 2 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/50249/mbox | git am -3
Learn more about email & git

[PATCH ed v4] add wq command Export this patch

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
Had to reintroduce the braces now that there are to expressions.
 command.ha | 10 +++++++++-
 error.ha   |  2 ++
 parse.ha   | 22 +++++++++++++++++++++-
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/command.ha b/command.ha
index c20b678..ccace0e 100644
--- a/command.ha
+++ b/command.ha
@@ -735,8 +735,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
index 957c61c..7ac4f78 100644
--- 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
index 8021f01..11ecbf2 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;
@@ -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)) {
--
2.44.0