# HG changeset patch # User samer # Date 1427287242 0 # Node ID e487c33c89ae6c663d710108911e3a6c407c4137 # Parent 0f96024b657ea82e5c3de6a50a583e319a49a28e Fixed exponential history file growth bug. diff -r 0f96024b657e -r e487c33c89ae .plrc --- a/.plrc Wed Mar 25 12:09:47 2015 +0000 +++ b/.plrc Wed Mar 25 12:40:42 2015 +0000 @@ -1,27 +1,29 @@ :- op(200,fy,@). +:- dynamic persistent_history_file/1. persistent_history(H) :- - debug(history,'Will use persistent history in "~s".',[H]), - prolog_history(disable), - (exists_file(H) -> rl_read_history(H); true), - history_sign_on(H), - periodic_save_history(H), - at_halt(history_sign_off(H)). + ( persistent_history_file(H) -> true + ; persistent_history_file(H1) -> throw(persistent_history_mismatch(H1,H)) + ; debug(history,'Will use persistent history in "~s".',[H]), + prolog_history(disable), + (exists_file(H) -> rl_read_history(H); true), + assert(persistent_history_file(H)), + current_prolog_flag(os_argv,ARGV), + atomics_to_string(ARGV," ",Command), + history_event('Start: ~s',[Command]), + periodic_save_history, + at_halt(history_event('Halt',[])) + ). -history_sign_on(H) :- - current_prolog_flag(os_argv,ARGV), +history_event(Msg,Args) :- + persistent_history_file(H), get_time(Now), - format_time(atom(Time),'%+',Now), - atomics_to_string(ARGV," ",Command), - format(atom(Header),'% Start: ~w - ~s\n',[Time,Command]), - rl_add_history(Header). - -history_sign_off(H) :- - get_time(Now), - format_time(atom(Time),'%+',Now), - atomics_to_string(ARGV," ",Command), - format(atom(Header),'% Halt: ~w\n',[Time]), - rl_add_history(Header). + format_time(string(Time),'%+',Now), + format(string(Info),Msg,Args), + format(atom(Line),'% ~w | ~s',[Time,Info]), + debug(history,'History event: ~s',[Line]), + rl_add_history(Line), + rl_write_history(H). periodic_save_history(H) :- debug(history,'Saving history to "~s"...',[H]),