~torresjrjr/public-inbox

ed: add wq command v3 PROPOSED

Curtis Arthaud: 1
 add wq command

 3 files changed, 30 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/50247/mbox | git am -3
Learn more about email & git

[PATCH ed v3] add wq command Export this patch

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
 command.ha |  7 +++++++
 error.ha   |  2 ++
 parse.ha   | 22 +++++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/command.ha b/command.ha
index c20b678..6b1d3ce 100644
--- a/command.ha
+++ b/command.ha
@@ -737,6 +737,13 @@ 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')
		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 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