>From 2e62e595c25446d5c18a33138f74bc9640be65b6 Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Mon, 16 Jul 2018 19:05:45 +1200 Subject: [PATCH] Only register REPL history hooks when csi is running interactively Fixes #1467. --- csi.scm | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) 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))) -- 2.11.0