From: Taylan Kammer <taylan.kammer@gmail.com>
To: 30600@debbugs.gnu.org
Subject: bug#30600: repl metacommands do not discard remaining input after syntax error in an expression
Date: Tue, 18 May 2021 18:19:30 +0200 [thread overview]
Message-ID: <0362f51c-6659-55f8-c3c0-02d4a63773b7@gmail.com> (raw)
In-Reply-To: <c468d921644b4fd5d19fbede4a0b1d89@airmail.cc>
[-- Attachment #1: Type: text/plain, Size: 51 bytes --]
Attached is a small patch to fix this.
--
Taylan
[-- Attachment #2: 0001-Better-REPL-behavior-on-syntax-errors-in-meta-comman.patch --]
[-- Type: text/plain, Size: 2868 bytes --]
From 0ba67891624647105e0dbdc33b0079cba655cec1 Mon Sep 17 00:00:00 2001
From: Taylan Kammer <taylan.kammer@gmail.com>
Date: Tue, 18 May 2021 18:15:08 +0200
Subject: [PATCH] Better REPL behavior on syntax errors in meta commands.
* module/system/repl/command.scm (define-meta-command): Flush all
remaining input after handling a read error.
* module/system/repl/common.scm (flush-all-input): New public procedure.
* module/system/repl/repl.scm: Remove local flush-all-input definition.
---
module/system/repl/command.scm | 5 ++++-
module/system/repl/common.scm | 9 ++++++++-
module/system/repl/repl.scm | 7 -------
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/module/system/repl/command.scm b/module/system/repl/command.scm
index ac1fa0933..c0649b60b 100644
--- a/module/system/repl/command.scm
+++ b/module/system/repl/command.scm
@@ -230,7 +230,10 @@
(lp (cons x out)))))))
(lambda (k . args)
(handle-read-error #f k args)))))
- (lambda (k) #f))))) ; the abort handler
+ ;; The abort handler:
+ (lambda (k)
+ (flush-all-input)
+ #f)))))
((_ ((name category) repl . datums) docstring b0 b1 ...)
(define-meta-command ((name category) repl () . datums)
diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
index 29ae104c5..51bf783e7 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -35,7 +35,7 @@
repl-expand repl-optimize
repl-parse repl-print repl-option-ref repl-option-set!
repl-default-option-set! repl-default-prompt-set!
- puts ->string user-error
+ puts ->string user-error flush-all-input
*warranty* *copying* *version*))
(define *version*
@@ -286,3 +286,10 @@ See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
(define (user-error msg . args)
(throw 'user-error #f msg args #f))
+
+(define (flush-all-input)
+ (if (and (char-ready?)
+ (not (eof-object? (peek-char))))
+ (begin
+ (read-char)
+ (flush-all-input))))
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm
index 5b27125f1..859ac444a 100644
--- a/module/system/repl/repl.scm
+++ b/module/system/repl/repl.scm
@@ -96,13 +96,6 @@
*unspecified*)
(else ((language-reader lang) port env))))))))
-(define (flush-all-input)
- (if (and (char-ready?)
- (not (eof-object? (peek-char))))
- (begin
- (read-char)
- (flush-all-input))))
-
;; repl-reader is a function defined in boot-9.scm, and is replaced by
;; something else if readline has been activated. much of this hoopla is
;; to be able to re-use the existing readline machinery.
--
2.30.2
prev parent reply other threads:[~2021-05-18 16:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-24 23:31 bug#30600: repl metacommands do not discard remaining input after syntax error in an expression dikbekulo
2021-05-18 16:19 ` Taylan Kammer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0362f51c-6659-55f8-c3c0-02d4a63773b7@gmail.com \
--to=taylan.kammer@gmail.com \
--cc=30600@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).