mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +02:00
Resetting history ring on empty input in repl.
This commit is contained in:
parent
f0dd9c9ddb
commit
f60617815d
3 changed files with 25 additions and 15 deletions
|
@ -158,7 +158,9 @@
|
|||
'completion: (make-sexp-buffer-completer))))))
|
||||
(cond
|
||||
((or (not line) (eof-object? line)))
|
||||
((equal? line "") (lp module env meta-env))
|
||||
((equal? line "")
|
||||
(history-reset! history)
|
||||
(lp module env meta-env))
|
||||
(else
|
||||
(history-commit! history line)
|
||||
(cond
|
||||
|
|
|
@ -22,17 +22,21 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; history
|
||||
|
||||
(define maximum-history-size 128)
|
||||
(define maximum-history-size 512)
|
||||
|
||||
(define-record-type History
|
||||
(%make-history remaining past future)
|
||||
(%make-history remaining past future filter)
|
||||
history?
|
||||
(remaining history-remaining history-remaining-set!)
|
||||
(past history-past history-past-set!)
|
||||
(future history-future history-future-set!))
|
||||
(future history-future history-future-set!)
|
||||
(filter history-filter history-filter-set!))
|
||||
|
||||
(define (make-history . o)
|
||||
(%make-history (if (pair? o) (car o) maximum-history-size) '() '()))
|
||||
(%make-history (if (pair? o) (car o) maximum-history-size)
|
||||
'()
|
||||
'()
|
||||
(and (pair? o) (pair? (cdr o)) (cadr o))))
|
||||
|
||||
(define (history-current h)
|
||||
(let ((p (history-past h)))
|
||||
|
@ -42,8 +46,9 @@
|
|||
(let ((past (history-past h)) (future (history-future h)))
|
||||
(if (pair? past) (cons (car past) (append future (cdr past))) future)))
|
||||
|
||||
(define (list->history ls)
|
||||
(%make-history (max maximum-history-size (length ls)) ls '()))
|
||||
(define (list->history ls . o)
|
||||
(%make-history (max maximum-history-size (length ls)) ls '()
|
||||
(and (pair? o) (car o))))
|
||||
|
||||
(define (history-flatten! h)
|
||||
(history-past-set! h (history->list h))
|
||||
|
@ -61,16 +66,19 @@
|
|||
|
||||
(define (history-insert! h x)
|
||||
(history-flatten! h)
|
||||
(history-past-push! h x))
|
||||
(if (not (and (history-filter h) ((history-filter h) x)))
|
||||
(history-past-push! h x)))
|
||||
|
||||
(define (history-commit! h x)
|
||||
(define (history-reset! h)
|
||||
(cond
|
||||
((pair? (history-future h))
|
||||
(history-past-set!
|
||||
h (cons x (append (drop-last (history-future h)) (history-past h))))
|
||||
(history-future-set! h '()))
|
||||
(else
|
||||
(history-insert! h x))))
|
||||
(history-past-set! h (append (drop-last (history-future h))
|
||||
(history-past h)))
|
||||
(history-future-set! h '()))))
|
||||
|
||||
(define (history-commit! h x)
|
||||
(history-reset! h)
|
||||
(history-insert! h x))
|
||||
|
||||
(define (history-prev! h)
|
||||
(let ((past (history-past h)))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
(define-library (chibi term edit-line)
|
||||
(export make-line-editor edit-line edit-line-repl
|
||||
make-history history-insert!
|
||||
make-history history-insert! history-reset!
|
||||
history-commit! history->list list->history buffer->string
|
||||
make-buffer buffer-make-completer
|
||||
buffer-clear buffer-refresh buffer-draw
|
||||
|
|
Loading…
Add table
Reference in a new issue