* boot-9.scm: Antirevert Jim's readline code which he reverted
authorMikael Djurfeldt <djurfeldt@nada.kth.se>
Tue, 12 May 1998 23:59:21 +0000 (23:59 +0000)
committerMikael Djurfeldt <djurfeldt@nada.kth.se>
Tue, 12 May 1998 23:59:21 +0000 (23:59 +0000)
19971027 and adapt it to the current readline interface.

* boot-9.scm (top-repl): Only enable readline if not using the
Emacs interface; Only use repl prompt when using the readline port
from repl-read.  (We don't want to see it when calling `read'.)

* boot-9.scm (remove-hook!): Parenthesis bug.

ice-9/boot-9.scm

index 19302af..6e38717 100644 (file)
   (procedure->macro
     (lambda (exp env)
       `(let ((thunk ,(caddr exp)))
-        (if (memq thunk ,(cadr exp)))
-        (set! ,(cadr exp)
-              (delq! thunk ,(cadr exp)))))))
+        (if (memq thunk ,(cadr exp))
+            (set! ,(cadr exp)
+                  (delq! thunk ,(cadr exp))))))))
 
 \f
 ;;; {Files}
 (define before-read-hook '())
 (define after-read-hook '())
 
+;;; The default repl-reader function.  We may override this if we've
+;;; the readline library.
+(define repl-reader
+  (lambda (prompt)
+    (display prompt)
+    (force-output)
+    (run-hooks before-read-hook)
+    (read (current-input-port))))
+
 (define (scm-style-repl)
   (letrec (
           (start-gc-rt #f)
           (start-rt #f)
-          (repl-report-reset (lambda () #f))
           (repl-report-start-timing (lambda ()
                                       (set! start-gc-rt (gc-run-time))
                                       (set! start-rt (get-internal-run-time))))
                 ((char=? ch #\newline)
                  (read-char))))))
           (-read (lambda ()
-                   (if scm-repl-prompt
-                       (begin
-                         (display (cond ((string? scm-repl-prompt)
-                                         scm-repl-prompt)
-                                        ((thunk? scm-repl-prompt)
-                                         (scm-repl-prompt))
-                                        (else "> ")))
-                         (force-output)
-                         (repl-report-reset)))
-                   (run-hooks before-read-hook)
-                   (let ((val (read (current-input-port))))
+                   (let ((val
+                          (let ((prompt (cond ((string? scm-repl-prompt)
+                                               scm-repl-prompt)
+                                              ((thunk? scm-repl-prompt)
+                                               (scm-repl-prompt))
+                                              (scm-repl-prompt "> ")
+                                              (else ""))))
+                            (repl-reader prompt))))
+
                      ;; As described in R4RS, the READ procedure updates the
                      ;; port to point to the first characetr past the end of
                      ;; the external representation of the object.  This
 
      ;; the protected thunk.
      (lambda ()
+
+       ;; If we've got readline, use it to prompt the user.  This is a
+       ;; kludge, but we'll fix it soon.  At least we only get
+       ;; readline involved when we're actually running the repl.
+       (if (and (memq 'readline *features*)
+               (not (and (module-defined? the-root-module
+                                          'use-emacs-interface)
+                         use-emacs-interface)))
+          (let ((read-hook (lambda () (run-hooks before-read-hook))))
+            (set-current-input-port (readline-port))
+            (set! repl-reader
+                  (lambda (prompt)
+                    (dynamic-wind
+                     (lambda ()
+                       (set-readline-prompt! prompt)
+                       (set-readline-read-hook! read-hook))
+                     (lambda () (read))
+                     (lambda ()
+                       (set-readline-prompt! "")
+                       (set-readline-read-hook! #f)))))))
        (scm-style-repl))
 
      ;; call at exit.
 (if (%search-load-path "ice-9/session.scm")
     (define-module (guile) :use-module (ice-9 session)))
 
-;;; {Use readline if present.}
+;;; Load readline code if readline primitives are available.
 ;;;
-
+;;; Ideally, we wouldn't do this until we were sure we were actually
+;;; going to enter the repl, but autoloading individual functions is
+;;; clumsy at the moment.
 (if (memq 'readline *features*)
     (define-module (guile) :use-module (ice-9 readline)))