summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2021-05-18 18:15:08 +0200
committerDaniel Llorens <lloda@sarc.name>2024-10-25 13:35:31 +0200
commit242e8698c2fdfada96a136abde5156bac3dbc6c9 (patch)
tree74722aac6a5bce90358e761af7e866dc9bb3d4e7
parent818b879b2e481943340e86dbb5b93f12021206c5 (diff)
downloadguile-242e8698c2fdfada96a136abde5156bac3dbc6c9.tar.gz
Better REPL behavior on syntax errors in meta commands.
Fixes <https://bugs.gnu.org/30600>. * 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.
-rw-r--r--module/system/repl/command.scm5
-rw-r--r--module/system/repl/common.scm9
-rw-r--r--module/system/repl/repl.scm7
3 files changed, 12 insertions, 9 deletions
diff --git a/module/system/repl/command.scm b/module/system/repl/command.scm
index 8b0422dbd..5b575f368 100644
--- a/module/system/repl/command.scm
+++ b/module/system/repl/command.scm
@@ -229,7 +229,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 a3f2032ba..46d0d5c04 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -33,7 +33,7 @@
repl-expand repl-optimize repl-optimize-cps
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*
@@ -297,3 +297,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 fc525b547..1c3407159 100644
--- a/module/system/repl/repl.scm
+++ b/module/system/repl/repl.scm
@@ -92,13 +92,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.