~ chicken-core (chicken-5) 42f3ff1bd63f563d3fd9c3329f0c5f9fc4f5b749


commit 42f3ff1bd63f563d3fd9c3329f0c5f9fc4f5b749
Author:     Evan Hanson <evhan@foldling.org>
AuthorDate: Mon Jul 16 19:05:45 2018 +1200
Commit:     Kooda <kooda@upyum.com>
CommitDate: Mon Jul 16 21:37:17 2018 +0200

    Only register REPL history hooks when csi is running interactively
    
    Fixes #1467.
    
    Signed-off-by: Kooda <kooda@upyum.com>

diff --git a/csi.scm b/csi.scm
index e7aa9459..89eefd6c 100644
--- a/csi.scm
+++ b/csi.scm
@@ -144,20 +144,6 @@ EOF
   (print +banner+ (chicken-version #t) "\n"))
 
 
-;;; Reader for REPL history:
-
-(set! ##sys#user-read-hook
-  (let ((old-hook ##sys#user-read-hook))
-    (lambda (char port)
-      (cond [(or (char=? #\) char) (char-whitespace? char))
-	     `',(history-ref (fx- history-count 1)) ]
-	    [else (old-hook char port)] ) ) ) )
-
-(set! ##sys#sharp-number-hook
-  (lambda (port n)
-    `',(history-ref n) ) )
-
-
 ;;; Chop terminating separator from pathname:
 
 (define (dirseparator? c)
@@ -207,7 +193,8 @@ EOF
 				   (loop (##sys#slot ps 1)) ) ) ) ) ) ] ) ) ) ) ) )
 				   
 
-;;; REPL customization:
+
+;;; REPL history references:
 
 (define history-list (make-vector 32))
 (define history-count 1)
@@ -244,6 +231,18 @@ EOF
 	(vector-ref history-list i) 
 	(##sys#error "history entry index out of range" index) ) ) )
 
+;;; Reader hooks for REPL history:
+
+(define (register-repl-history!)
+  (set! ##sys#user-read-hook
+    (let ((old-hook ##sys#user-read-hook))
+      (lambda (char port)
+	(cond ((or (char=? #\) char) (char-whitespace? char))
+	       `',(history-ref (fx- history-count 1)))
+	      (else (old-hook char port))))))
+  (set! ##sys#sharp-number-hook
+    (lambda (port n) `',(history-ref n))))
+
 (repl-prompt
  (let ((sprintf sprintf))
    (lambda ()
@@ -254,6 +253,9 @@ EOF
 	     ""))
        history-count))))
 
+
+;;; Other REPL customizations:
+
 (define (tty-input?)
   (or (##core#inline "C_i_tty_forcedp")
       (##sys#tty-port? ##sys#standard-input)))
@@ -1083,7 +1085,8 @@ EOF
 	(set! ##sys#notices-enabled #f))
       (do ([args args (cdr args)])
 	  ((null? args)
-	   (unless batch 
+	   (unless batch
+	     (register-repl-history!)
 	     (repl csi-eval)
 	     (##sys#write-char-0 #\newline ##sys#standard-output) ) )
 	(let* ((arg (car args)))
Trap