mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +02:00
Allowing multi-line input to (chibi repl) from Emacs and raw terminals.
This commit is contained in:
parent
b9bf656d2b
commit
966ece57c2
1 changed files with 18 additions and 3 deletions
|
@ -28,11 +28,26 @@
|
|||
(define (write-to-string x)
|
||||
(call-with-output-string (lambda (out) (write x out))))
|
||||
|
||||
(define (buffer-complete-sexp? buf)
|
||||
(call-with-input-string (buffer->string buf)
|
||||
(define (complete-sexp? str)
|
||||
(call-with-input-string str
|
||||
(lambda (in)
|
||||
(let lp () (if (not (eof-object? (read/ss in))) (lp))))))
|
||||
|
||||
(define (read-line/complete-sexp in)
|
||||
(let lp ((res ""))
|
||||
(let ((line (read-line in)))
|
||||
(cond
|
||||
((eof-object? line)
|
||||
(if (equal? res "") line res))
|
||||
(else
|
||||
(let ((res (string-append res line "\n")))
|
||||
(if (guard (exn (else #f)) (complete-sexp? res))
|
||||
res
|
||||
(lp res))))))))
|
||||
|
||||
(define (buffer-complete-sexp? buf)
|
||||
(complete-sexp? (buffer->string buf)))
|
||||
|
||||
(define module? vector?)
|
||||
(define (module-env mod) (vector-ref mod 1))
|
||||
|
||||
|
@ -149,7 +164,7 @@
|
|||
(raw?
|
||||
(display prompt out)
|
||||
(flush-output out)
|
||||
(read-line in))
|
||||
(read-line/complete-sexp in))
|
||||
(else
|
||||
(edit-line in out
|
||||
'prompt: prompt
|
||||
|
|
Loading…
Add table
Reference in a new issue