repl read errors should print the error and resume editing the same input with no newline

This commit is contained in:
Alex Shinn 2011-10-30 16:10:32 +09:00
parent 374d61c98e
commit 190c962433
2 changed files with 24 additions and 18 deletions

View file

@ -29,11 +29,9 @@
(call-with-output-string (lambda (out) (write x out)))) (call-with-output-string (lambda (out) (write x out))))
(define (buffer-complete-sexp? buf) (define (buffer-complete-sexp? buf)
(guard (exn (else #f)) (call-with-input-string (buffer->string buf)
(call-with-input-string (buffer->string buf) (lambda (in)
(lambda (in) (let lp () (if (not (eof-object? (read/ss in))) (lp))))))
(let lp () (if (not (eof-object? (read/ss in))) (lp)))))
#t))
(define module? vector?) (define module? vector?)
(define (module-env mod) (vector-ref mod 1)) (define (module-env mod) (vector-ref mod 1))

View file

@ -188,19 +188,23 @@
(else (else
(lp (+ i 1) row (+ col 1))))))) (lp (+ i 1) row (+ col 1)))))))
(define (buffer-clear buf out)
;; goto start of input
(terminal-goto-col out 0)
(if (positive? (buffer-row buf))
(terminal-up out (buffer-row buf)))
;; clear below
(terminal-clear-below out))
(define (buffer-draw buf out) (define (buffer-draw buf out)
(let* ((gap (buffer-gap buf)) (let* ((gap (buffer-gap buf))
(str (buffer-string buf)) (str (buffer-string buf))
(end (string-length str)) (end (string-length str))
(old-row (buffer-row buf)) (old-row (buffer-row buf))
(old-col (buffer-col buf))) (old-col (buffer-col buf)))
;; update position and clear the current input
(buffer-clear buf out)
(buffer-update-position! buf) (buffer-update-position! buf)
;; goto start of input
(terminal-goto-col out 0)
(if (positive? old-row)
(terminal-up out old-row))
;; clear and display new buffer
(terminal-clear-below out)
(display (substring str 0 (buffer-pos buf)) out) (display (substring str 0 (buffer-pos buf)) out)
(display (substring str (buffer-gap buf) end) out) (display (substring str (buffer-gap buf) end) out)
;; move to next line if point at eol ;; move to next line if point at eol
@ -361,13 +365,17 @@
(buffer-insert! buf out ch)) (buffer-insert! buf out ch))
(define (command/enter ch buf out return) (define (command/enter ch buf out return)
(cond (guard (exn (else
(((buffer-complete? buf) buf) (buffer-clear buf out)
(command/end-of-line ch buf out return) (print-exception exn out)
(newline out) (buffer-draw buf out)))
(return)) (cond
(else (((buffer-complete? buf) buf)
(command/self-insert ch buf out return)))) (command/end-of-line ch buf out return)
(newline out)
(return))
(else
(command/self-insert ch buf out return)))))
(define (command/beep ch buf out return) (define (command/beep ch buf out return)
(write-char (integer->char 7) out)) (write-char (integer->char 7) out))