# HG changeset patch # User daniel # Date 1431614283 -3600 # Node ID 6fea6e085b8128d95ce0cc446cb5164044c16503 # Parent c7720fefea264c89ab6aff21fc54a93cdbb7a88b Added some hg ignores, added .swiplrc for swipl >=7.3.0 diff -r c7720fefea26 -r 6fea6e085b81 .hgignore --- a/.hgignore Thu May 14 15:35:04 2015 +0100 +++ b/.hgignore Thu May 14 15:38:03 2015 +0100 @@ -44,3 +44,7 @@ ^.Rprofile ^.julia_history ^var/dml/.dml.history +^var/dml/httpd.log +^.xpce/ +^.elinks/ +^.blackboxrc diff -r c7720fefea26 -r 6fea6e085b81 .swiplrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.swiplrc Thu May 14 15:38:03 2015 +0100 @@ -0,0 +1,87 @@ +:- op(200,fy,@). + +:- dynamic persistent_history_file/1. +persistent_history(H) :- persistent_history(H,60). +persistent_history(H,Interval) :- + ( persistent_history_file(H) -> true + ; persistent_history_file(H1) -> throw(persistent_history_mismatch(H1,H)) + ; debug(history,'Will use persistent history in "~s", saving every ~d seconds.',[H,Interval]), + 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(Interval), + at_halt(history_event('Halt',[])) + ). + +history_event(Msg,Args) :- + persistent_history_file(H), + get_time(Now), + 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(Interval) :- + persistent_history_file(H), + debug(history,'Saving history to "~s"...',[H]), + rl_write_history(H), + alarm(Interval,periodic_save_history(Interval),_,[remove(true)]). + +colour_terminal :- + stream_property(user_output, tty(true)), + getenv('TERM',Term), + member(Term,[xterm,screen,'screen-256color','xterm-256color','xterm-color']). + +:- dynamic http_proxy/3. + +get_http_proxy(Host,Port,basic(User,Pwd)) :- + getenv(use_proxy,yes), + getenv(http_proxy,Proxy), + % proxy looks like http://User:Password@Host:Port + atom_concat('http://',Proxy1,Proxy), % strip off protocol + split_atom(Proxy1,Auth,'@',HostPort), + split_atom(Auth,User,':',Pwd), + split_atom(HostPort,Host,':',APort), + atom_number(APort,Port). + +split_atom(Atom,Pre,Mid,Post) :- + sub_atom(Atom,LPre,_,LPost,Mid), + sub_atom(Atom,0,LPre,_,Pre), + sub_atom(Atom,_,LPost,0,Post). + +internal_host(localhost). +internal_host(Host) :- sub_atom(Host,_,_,0,'bl.uk'). + +:- multifile http:open_options/2. +http:open_options(Parts,[proxy(Host,Port),proxy_authorization(Auth)|Opts]) :- + http_proxy(Host,Port,Auth), + option(host(Target),Parts), + \+internal_host(Target), + debug(proxy,'Using HTTP proxy ~w:~w for ~w',[Host,Port,Target]), + debug(proxy,'Parts: ~w',[Parts]), + ( option(scheme(https),Parts) + -> debug(proxy,'Using HTTPS',[]), + Opts=[cert_verify_hook(verify_certificate)] + ; Opts=[] + ). + +verify_certificate(_,_,_,_,_) :- format(user_error,'Accepting certificate\n',[]). + +:- %persistent_history('.swipl_history'), + (colour_terminal -> load_files(library(ansi_term), [silent(true)]); true), + set_prolog_flag(prompt_alternatives_on, determinism), + set_prolog_flag(editor, '$EDITOR'), + load_files(library(url), [silent(true)]), + load_files(library(http/http_ssl_plugin), [silent(true)]), + ( get_http_proxy(Host,Port,Auth) + -> assert(http_proxy(Host,Port,Auth)) + ; true + ). + +