mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 13:24:46 +00:00
Add tab completion to REPL
This commit is contained in:
parent
7fd0005735
commit
4475fc7cf4
13
bin/madlisp
13
bin/madlisp
@ -43,6 +43,19 @@ function ml_repl($lisp)
|
|||||||
readline_read_history($historyFile);
|
readline_read_history($historyFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tab-completion
|
||||||
|
$completions = array_keys($lisp->getEnv()->getRoot()->getData());
|
||||||
|
sort($completions);
|
||||||
|
readline_completion_function(function ($word, $start, $end) use ($completions) {
|
||||||
|
$matches = [];
|
||||||
|
foreach ($completions as $comp) {
|
||||||
|
if ($word == substr($comp, 0, strlen($word))) {
|
||||||
|
$matches[] = $comp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $matches;
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$input = readline('> ');
|
$input = readline('> ');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user