mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 14:49:18 +02:00
Adding tab-completion on all identifiers in the current environment.
This commit is contained in:
parent
81567045f3
commit
aa07c6b022
2 changed files with 20 additions and 2 deletions
|
@ -36,6 +36,23 @@
|
||||||
(define module? vector?)
|
(define module? vector?)
|
||||||
(define (module-env mod) (vector-ref mod 1))
|
(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,
|
;;> Runs an interactive REPL. Repeatedly displays a prompt,
|
||||||
;;> then Reads an expression, Evaluates the expression, Prints
|
;;> then Reads an expression, Evaluates the expression, Prints
|
||||||
;;> the result then Loops. Terminates when the end of input is
|
;;> the result then Loops. Terminates when the end of input is
|
||||||
|
@ -108,7 +125,8 @@
|
||||||
(edit-line in out
|
(edit-line in out
|
||||||
'prompt: prompt
|
'prompt: prompt
|
||||||
'history: history
|
'history: history
|
||||||
'complete?: buffer-complete-sexp?)))))
|
'complete?: buffer-complete-sexp?
|
||||||
|
'completion: (make-sexp-buffer-completer))))))
|
||||||
(cond
|
(cond
|
||||||
((or (not line) (eof-object? line)))
|
((or (not line) (eof-object? line)))
|
||||||
((equal? line "") (lp module env meta-env))
|
((equal? line "") (lp module env meta-env))
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
(export repl)
|
(export repl)
|
||||||
(import (scheme) (only (meta) load-module)
|
(import (scheme) (only (meta) load-module)
|
||||||
(chibi ast) (chibi io) (chibi process) (chibi term edit-line)
|
(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"))
|
(include "repl.scm"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue