bug#30600: repl metacommands do not discard remaining input after syntax error in an expression

Taylan Kammer <[email protected]>
Newsgroups gmane.lisp.guile.bugs
Message-ID <[email protected]>
Attached is a small patch to fix this.

-- 
Taylan
0001-Better-REPL-behavior-on-syntax-errors-in-meta-comman.patch (text/plain, 2.8 KB)
From 0ba67891624647105e0dbdc33b0079cba655cec1 Mon Sep 17 00:00:00 2001
From: Taylan Kammer <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.