save history for readline

This commit is contained in:
Pekka Laiho 2020-06-06 20:12:45 +07:00
parent 75861bf1c7
commit 01d429324e

View File

@ -3,6 +3,12 @@ require('bootstrap.php');
list($lisp, $rootEnv) = ml_get_lisp(); list($lisp, $rootEnv) = ml_get_lisp();
// Read history
$historyFile = $_SERVER['HOME'] . '/.madlisp_history';
if (is_readable($historyFile)) {
readline_read_history($historyFile);
}
// Create new env for user definitions // Create new env for user definitions
$userEnv = new MadLisp\Env('repl', $rootEnv); $userEnv = new MadLisp\Env('repl', $rootEnv);
@ -11,6 +17,11 @@ while (true) {
try { try {
$lisp->rep($input, $userEnv); $lisp->rep($input, $userEnv);
if ($input) {
readline_add_history($input);
readline_write_history($historyFile);
}
} catch (MadLisp\MadLispException $ex) { } catch (MadLisp\MadLispException $ex) {
print('error: ' . $ex->getMessage()); print('error: ' . $ex->getMessage());
} catch (TypeError $ex) { } catch (TypeError $ex) {