emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/racket-mode fd44a86d1c 1/2: Discard subsequent lines of in


From: ELPA Syncer
Subject: [nongnu] elpa/racket-mode fd44a86d1c 1/2: Discard subsequent lines of input after exn:fail:read
Date: Fri, 16 Dec 2022 13:59:30 -0500 (EST)

branch: elpa/racket-mode
commit fd44a86d1c826cc8099226c7a02c3a0e184a563e
Author: Greg Hendershott <git@greghendershott.com>
Commit: Greg Hendershott <git@greghendershott.com>

    Discard subsequent lines of input after exn:fail:read
    
    This handles cases like #646 where reading "\?"\n errors on the bad \?
    escape sequence, leaving the "\n unconsumed from the input port. This
    seems like a reasonable mitigation, although I'm not 100% confident
    this won't introduce new problems.
    
    [A potentially more reliable (but more drastic) change would be to stop
    having the REPL consume interactions from an input port that is
    directly connected to the Emacs REPL buffer -- instead, submit to the
    back end as a "REPL interaction" command. This would make explicit the
    extent of each interaction's input, rather than consuming all pending
    lines. There could also be a UI similar to Dr Racket's, for when the
    user's program is reading input. But for now, I think all that would
    be a solution in search of a problem that few people are
    experiencing.]
    
    Also change some `cond` and `match` expressions to sequential uses of
    `when` with side effects, to be clearer what's really going on.
---
 racket/interactions.rkt | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/racket/interactions.rkt b/racket/interactions.rkt
index 38ce16b4ec..4aa62a3a88 100644
--- a/racket/interactions.rkt
+++ b/racket/interactions.rkt
@@ -19,32 +19,40 @@
 ;; abandoned tcp-input-port. So give up on that, reverting issue #305.
 
 (define (get-interaction prompt)
+  ;; Need to port-count-lines! here -- not sufficient to do once to
+  ;; REPL TCP input port upon connection -- because racket/gui/base
+  ;; sets current-get-interaction-port to wrap the original input
+  ;; port. See issues #519 #556.
+  (define in ((current-get-interaction-input-port)))
+  (port-count-lines! in)
   ;; Using with-handlers here would be a mistake; see #543.
   (call-with-exception-handler
    (λ (e)
-     (cond [(exn:fail:network? e)
-            (log-racket-mode-info "get-interaction: exn:fail:network")
-            (exit 'get-interaction-exn:fail:network)]
-           [else e]))
+     (when (exn:fail:network? e)
+        (log-racket-mode-info "get-interaction: exn:fail:network")
+        (exit 'get-interaction-exn:fail:network))
+     (when (exn:fail:read? e) ;#646
+        (discard-remaining-lines! in)
+        (zero-column!))
+     e)
    (λ ()
-     (define in ((current-get-interaction-input-port)))
-     ;; Need to port-count-lines! here -- not sufficient to do to REPL
-     ;; TCP input port upon connection -- because racket/gui/base sets
-     ;; current-get-interaction-port to wrap the original input port.
-     ;; See issues #519 #556.
-     (port-count-lines! in)
      (unless (already-more-to-read? in) ;#311
        (display-prompt prompt))
-     (match (with-stack-checkpoint
-              ((current-read-interaction) prompt in))
-       [(? eof-object?)
-        (log-racket-mode-info "get-interaction: eof")
-        (display-commented
-         "Closing REPL session because language's current-read-interaction 
returned EOF")
-        (exit 'get-interaction-eof)]
-       [v
-        (zero-column!)
-        v]))))
+     (define v (with-stack-checkpoint
+                 ((current-read-interaction) prompt in)))
+     (when (eof-object? v)
+       (log-racket-mode-info "get-interaction: eof")
+       (display-commented
+        "Closing REPL session because language's current-read-interaction 
returned EOF")
+       (exit 'get-interaction-eof))
+     (zero-column!)
+     v)))
+
+(define (discard-remaining-lines! in)
+  (define (f)
+    (void (read-line in))
+    (f))
+  (sync/timeout 0.1 (thread f)))
 
 (define (already-more-to-read? in)
   ;; Is there already at least one more expression available to read



reply via email to

[Prev in Thread] Current Thread [Next in Thread]