expand((:- meta_predicate '~~'(_X)),_Layout1,_Term2,_Layout2) :- !,
%print(not_removing_in_meta_predicate('~~'(_X))),nl,
fail.
expand((:- use_module(library(Lib))),Layout1,Term2,Layout2) :-
library_to_patch(Lib,PatchedLib),
(prolog_load_context(module,CurModule) -> true ; CurModule=user),
\+ ignore_patches_in_module(CurModule),
!,
Layout2 = Layout1,
format('Patching use_module(library(~w)) in ~w to ~w~n',[Lib,CurModule,PatchedLib]),
Term2 = (:- use_module(PatchedLib)).
expand((:- use_module(library(Lib),Preds)),Layout1,Term2,Layout2) :-
library_to_patch(Lib,PatchedLib),
Preds \= [], % so that there is a way to bypass the term expander
current_module(CurModule),
(prolog_load_context(module,CurModule) -> true ; CurModule=user),
\+ ignore_patches_in_module(CurModule),
!,
Layout2 = Layout1,
format('Patching use_module(library(~w),~w) in ~w to ~w~n',[Lib,Preds,CurModule,PatchedLib]),
Term2 = (:- use_module(PatchedLib,Preds)).
expand(Term1,Layout1,Term2,Layout2) :-
% removes terms like ~~ pp_mnf,...
debugging_calls:remove_debugging_calls(Layout1,Term1,Layout2,Term2).