From 4475fc7cf437ee380330ca52cd007fb2dc0ee86c Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Fri, 25 Dec 2020 09:22:47 +0700 Subject: [PATCH] Add tab completion to REPL --- bin/madlisp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bin/madlisp b/bin/madlisp index d0d8b40..05fad94 100755 --- a/bin/madlisp +++ b/bin/madlisp @@ -43,6 +43,19 @@ function ml_repl($lisp) 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) { $input = readline('> ');