diff --git a/lib/chibi/repl.scm b/lib/chibi/repl.scm index 86d87d13..1437e62d 100644 --- a/lib/chibi/repl.scm +++ b/lib/chibi/repl.scm @@ -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 diff --git a/lib/chibi/term/edit-line.scm b/lib/chibi/term/edit-line.scm index 7292e4e1..b7d50f9c 100644 --- a/lib/chibi/term/edit-line.scm +++ b/lib/chibi/term/edit-line.scm @@ -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))) diff --git a/lib/chibi/term/edit-line.sld b/lib/chibi/term/edit-line.sld index 258c2b6c..9c4fbca3 100644 --- a/lib/chibi/term/edit-line.sld +++ b/lib/chibi/term/edit-line.sld @@ -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