mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-09 14:07:34 +02:00
repl read errors should print the error and resume editing the same input with no newline
This commit is contained in:
parent
374d61c98e
commit
190c962433
2 changed files with 24 additions and 18 deletions
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue