From: Eshel Yaron Date: Fri, 21 Oct 2022 08:32:10 +0000 (+0300) Subject: ENHANCED: add predicate properties list in help buffers X-Git-Tag: V8.5.20-sweep-0.8.0~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d3e7b8b4b3be012ca1e9ad10336fc9eda65a8bfc;p=sweep.git ENHANCED: add predicate properties list in help buffers * sweep.pl (sweep_predicate_properties/2): new predicate. * sweeprolog.el (sweeprolog--render-predicate-properties): new function. (sweeprolog--describe-predicate): use it. --- diff --git a/sweep.pl b/sweep.pl index 27b169d..7b4a8d0 100644 --- a/sweep.pl +++ b/sweep.pl @@ -63,7 +63,8 @@ sweep_local_predicate_export_comment/2, write_sweep_module_location/0, sweep_module_html_documentation/2, - sweep_predicate_html_documentation/2 + sweep_predicate_html_documentation/2, + sweep_predicate_properties/2 ]). :- use_module(library(pldoc)). @@ -435,6 +436,11 @@ sweep_module_path_(Module, Path) :- sweep_module_path_(Module, Path) :- '$autoload':library_index(_, Module, Path0), !, string_concat(Path0, ".pl", Path). +sweep_predicate_properties(P0, Props) :- + term_string(P, P0), + pi_head(P, Head), + findall(Prop, predicate_property(Head, Prop), Props). + sweep_predicate_html_documentation(P0, D) :- term_string(P1, P0), ( P1 = M:F/N diff --git a/sweeprolog.el b/sweeprolog.el index 54812e2..838eb05 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -3165,17 +3165,65 @@ if-then-else constructs in SWI-Prolog." (interactive (list (sweeprolog-read-module-name))) (sweeprolog--describe-module mod)) +(defun sweeprolog--render-predicate-properties (props) + (concat + "\n\nPredicate properties: " + (string-join + (delq nil + (mapcar + (lambda (prop) + (pcase prop + (`(atom . "built_in") "built-in") + (`(atom . "dynamic") "dynamic") + (`(atom . "foreign") "foreign") + (`(atom . "quasi_quotation_syntax") + "defines a quasi-quotation syntax") + (`(atom . "ssu") + "defined using single sided unification rules") + (`(atom . "tabled") "tabled") + (`(atom . "thread_local") "thread-local") + (`(atom . "transparent") "module-transparent") + (`(atom . "volatile") "volatile.") + (`(atom . "iso") "specified in the ISO standard") + (`(atom . "multifile") "multifile") + (`(compound "meta_predicate" . ,_) "meta-predicate") + (`(atom . "non_terminal") "DCG non-terminal") + (`(compound "size" ,s) (concat (number-to-string s) + " bytes")) + (`(compound "number_of_clauses" ,n) + (concat "has " + (pcase n + (1 "one clause") + (_ (concat (number-to-string n) + " clauses"))))) + (`(atom . "det") "deterministic") + (`(atom . "discontiguous") "discontiguous") + (`(atom . "exported") "exported"))) + props)) + ", ") + ".")) + (defun sweeprolog--describe-predicate (pred) (let ((page (progn (sweeprolog--open-query "user" - "sweep" - "sweep_predicate_html_documentation" - pred) + "sweep" + "sweep_predicate_html_documentation" + pred) (let ((sol (sweeprolog-next-solution))) (sweeprolog-close-query) (when (sweeprolog-true-p sol) (sweeprolog-render-html (cdr sol)))))) + (props + (progn + (sweeprolog--open-query "user" + "sweep" + "sweep_predicate_properties" + pred) + (let ((sol (sweeprolog-next-solution))) + (sweeprolog-close-query) + (when (sweeprolog-true-p sol) + (cdr sol))))) (path (car (sweeprolog-predicate-location pred)))) (help-setup-xref (list #'sweeprolog--describe-predicate pred) (called-interactively-p 'interactive)) @@ -3190,10 +3238,13 @@ if-then-else constructs in SWI-Prolog." (if page (concat " is a SWI-Prolog predicate.\n\n" page) - " is an undocumented SWI-Prolog predicate."))) + " is an undocumented SWI-Prolog predicate.") + (when props + (sweeprolog--render-predicate-properties props)))) (if page - (insert pred " is a built-in SWI-Prolog predicate.\n\n" - page) + (insert pred " is a SWI-Prolog predicate.\n\n" page + (when props + (sweeprolog--render-predicate-properties props))) (insert pred " is not documented as a SWI-Prolog predicate."))))))) ;;;###autoload