From 190c9624339a08b83f4742390f9f18960dffe295 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 30 Oct 2011 16:10:32 +0900 Subject: [PATCH] repl read errors should print the error and resume editing the same input with no newline --- lib/chibi/repl.scm | 8 +++----- lib/chibi/term/edit-line.scm | 34 +++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/chibi/repl.scm b/lib/chibi/repl.scm index 450242d9..30321fe4 100644 --- a/lib/chibi/repl.scm +++ b/lib/chibi/repl.scm @@ -29,11 +29,9 @@ (call-with-output-string (lambda (out) (write x out)))) (define (buffer-complete-sexp? buf) - (guard (exn (else #f)) - (call-with-input-string (buffer->string buf) - (lambda (in) - (let lp () (if (not (eof-object? (read/ss in))) (lp))))) - #t)) + (call-with-input-string (buffer->string buf) + (lambda (in) + (let lp () (if (not (eof-object? (read/ss in))) (lp)))))) (define module? vector?) (define (module-env mod) (vector-ref mod 1)) diff --git a/lib/chibi/term/edit-line.scm b/lib/chibi/term/edit-line.scm index 9808a480..2840f507 100644 --- a/lib/chibi/term/edit-line.scm +++ b/lib/chibi/term/edit-line.scm @@ -188,19 +188,23 @@ (else (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) (let* ((gap (buffer-gap buf)) (str (buffer-string buf)) (end (string-length str)) (old-row (buffer-row buf)) (old-col (buffer-col buf))) + ;; update position and clear the current input + (buffer-clear buf out) (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 (buffer-gap buf) end) out) ;; move to next line if point at eol @@ -361,13 +365,17 @@ (buffer-insert! buf out ch)) (define (command/enter ch buf out return) - (cond - (((buffer-complete? buf) buf) - (command/end-of-line ch buf out return) - (newline out) - (return)) - (else - (command/self-insert ch buf out return)))) + (guard (exn (else + (buffer-clear buf out) + (print-exception exn out) + (buffer-draw buf out))) + (cond + (((buffer-complete? buf) buf) + (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) (write-char (integer->char 7) out))