summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-07 20:47:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-07 20:47:57 -0700
commitb1c2b8641f584ddeaef872ee6425cadca706e97d (patch)
tree6d01c1623c6368e3a12456e23944892fd5324d7e /parser.c
parentac22923c691dfaf40830bedf056ee8948427dced (diff)
downloadtxr-b1c2b8641f584ddeaef872ee6425cadca706e97d.tar.gz
txr-b1c2b8641f584ddeaef872ee6425cadca706e97d.tar.bz2
txr-b1c2b8641f584ddeaef872ee6425cadca706e97d.zip
Load and save repl history.
* parser.c (repl): If a HOME environment variable exists, then load the .txr_history file from the user's home directory and save it when exiting. * sysif.c (getenv_wrap): Static function changed to extern. * sysif.h (getenv_wrap): Declared.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/parser.c b/parser.c
index 532936f0..6b5a0593 100644
--- a/parser.c
+++ b/parser.c
@@ -48,6 +48,7 @@
#include "eval.h"
#include "stream.h"
#include "y.tab.h"
+#include "sysif.h"
#include "parser.h"
#if HAVE_TERMIOS
#include "linenoise/linenoise.h"
@@ -515,12 +516,18 @@ val repl(val bindings, val in_stream, val out_stream)
val result_hash = make_hash(nil, nil, nil);
val done = nil;
val counter = one;
+ val home = getenv_wrap(lit("HOME"));
+ val histfile = if2(home, format(nil, lit("~a/.txr_history"), home, nao));
+ char *histfile_u8 = utf8_dup_to(c_str(histfile));
val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr));
reg_varl(result_hash_sym, result_hash);
lino_set_completion_cb(ls, provide_completions, 0);
+ if (histfile)
+ lino_hist_load(ls, histfile_u8);
+
while (!done) {
val prompt = format(nil, lit("~a> "), counter, nao);
val prev_counter = counter;
@@ -597,9 +604,16 @@ val repl(val bindings, val in_stream, val out_stream)
}
set_sig_handler(num(SIGINT), old_sig_handler);
+
+
+ if (histfile)
+ lino_hist_save(ls, histfile_u8);
+
+ free(histfile_u8);
free(prompt_u8);
free(line_u8);
lino_free(ls);
+ gc_hint(histfile);
return nil;
}