Adding tab-completion on all identifiers in the current environment.

This commit is contained in:
Alex Shinn 2011-12-04 20:35:41 +09:00
parent 81567045f3
commit aa07c6b022
2 changed files with 20 additions and 2 deletions

View file

@ -36,6 +36,23 @@
(define module? vector?)
(define (module-env mod) (vector-ref mod 1))
(define (all-exports env)
(let lp ((env env) (res '()))
(if (not env)
res
(lp (environment-parent env) (append (env-exports env) res)))))
(define (make-sexp-buffer-completer)
(buffer-make-completer
(lambda (buf word)
(let ((len (string-length word)))
(sort
(filter
(lambda (w)
(and (>= (string-length w) len)
(equal? word (substring w 0 len))))
(map symbol->string (all-exports (interaction-environment)))))))))
;;> Runs an interactive REPL. Repeatedly displays a prompt,
;;> then Reads an expression, Evaluates the expression, Prints
;;> the result then Loops. Terminates when the end of input is
@ -108,7 +125,8 @@
(edit-line in out
'prompt: prompt
'history: history
'complete?: buffer-complete-sexp?)))))
'complete?: buffer-complete-sexp?
'completion: (make-sexp-buffer-completer))))))
(cond
((or (not line) (eof-object? line)))
((equal? line "") (lp module env meta-env))

View file

@ -3,5 +3,5 @@
(export repl)
(import (scheme) (only (meta) load-module)
(chibi ast) (chibi io) (chibi process) (chibi term edit-line)
(srfi 18) (srfi 38) (srfi 98))
(srfi 1) (srfi 18) (srfi 38) (srfi 95) (srfi 98))
(include "repl.scm"))