1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/* Part of XPCE --- The SWI-Prolog GUI toolkit
Author: Jan Wielemaker and Anjo Anjewierden
E-mail: J.Wielemaker@vu.nl
WWW: http://www.swi-prolog.org/packages/xpce/
Copyright (c) 1996-2012, University of Amsterdam
VU University Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
:- module(pce_compatibility_layer,
[ auto_call/1,
callable_predicate/1,
modified_since_last_loaded/1,
pce_error/1,
pce_warn/1,
pce_info/1
]).
/** <module> XPCE Compatibility layer
This layer defines some predicates to enhance portability with SICStus
and Quintus Prolog. These systems are no longer supported, but it is
probably wise to keep this layer for `just-in-case'.
*/
:- meta_predicate
auto_call(0),
callable_predicate(:).
%! auto_call(:Goal)
%
% Autoload Goal and call it. If autoloading is enabled we can simply
% call the target. Otherwise we autoload the predicate and
% subsequently call it.
%
% This predicate should be used to open new IDE tools, for example the
% manual opening the editor, etc.
auto_call(G) :-
current_prolog_flag(autoload, true),
!,
call(G).
auto_call(G) :-
'$pi_head'(PI, G),
current_prolog_flag(autoload, Old),
setup_call_cleanup(
asserta(user:thread_message_hook(autoload(disabled(_Count)),_,_), Ref),
setup_call_cleanup(
set_prolog_flag(autoload, true),
'$autoload'(PI),
set_prolog_flag(autoload, Old)),
erase(Ref)),
call(G).
/*******************************
* DIALOG EDITOR SUPPORT *
*******************************/
%! callable_predicate(:Head) is semidet.
%
% Succeeds if Head can be called without raising an exception for
% an undefined predicate
callable_predicate(M:Head) :-
callable(Head),
functor(Head, Name, Arity),
current_predicate(M:Name/Arity).
%! modified_since_last_loaded(Path) is semidet.
%
% True is file has been modified since the last time it was loaded.
modified_since_last_loaded(File) :-
'$time_source_file'(File, LoadTime, user),
!,
time_file(File, Modified),
Modified > LoadTime.
modified_since_last_loaded(InFile) :-
'$time_source_file'(File, LoadTime, user),
same_file(InFile, File),
!,
time_file(File, Modified),
Modified > LoadTime.
/*******************************
* MESSAGES *
*******************************/
%! pce_error(+Term) is det.
%! pce_warn(+Term) is det.
%! pce_info(+Term) is det.
%
% Portability layer wrappers around print_message/2.
pce_error(Term) :-
( current_prolog_flag(xref, true)
-> true
; print_message(error, Term)
).
pce_warn(Term) :-
( current_prolog_flag(xref, true)
-> true
; print_message(warning, Term)
).
pce_info(Term) :-
print_message(informational, Term).
|