branch: elpa/sweeprolog
commit d0e96f9230095fb35ef5452f745c0dc9e2209ef7
Author: Eshel Yaron <m...@eshelyaron.com>
Commit: Eshel Yaron <m...@eshelyaron.com>

    ADDED: on-the-fly documentation for predicates with eldoc
---
 sweep.pl      | 18 ++++++------------
 sweeprolog.el | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/sweep.pl b/sweep.pl
index b445260711..41b3618a1d 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -129,7 +129,7 @@ sweep_colourise_buffer_(Path0, Contents, []) :-
     get_time(Time),
     asserta(sweep_open(Path, Contents), Ref0),
     asserta(sweep_source_time(Path, Time), Ref1),
-    xref_source(Path, []),
+    xref_source(Path, [comments(store)]),
     seek(Contents, 0, bof, _),
     retractall(sweep_current_comment(_, _, _)),
     prolog_colourise_stream(Contents,
@@ -249,6 +249,7 @@ sweep_handle_identifier_at_point_goal(_Path, _M0, built_in, 
Goal) :-
 sweep_handle_identifier_at_point_goal(_Path, _M0, imported(Path), Goal) :-
     !,
     pi_head(PI, Goal),
+    xref_source(Path, [comments(store)]),
     xref_module(Path, M),
     asserta(sweep_current_identifier_at_point(M:PI)).
 sweep_handle_identifier_at_point_goal(_Path, _M0, Extern, Goal) :-
@@ -331,18 +332,11 @@ sweep_colourise_some_terms_(Path0, Offset, Contents, []) 
:-
              user:sweep_funcall("sweeprolog--colourise", 
[Start,Len,"comment"|String], _)
            )).
 
-sweep_documentation([Path, Functor, Arity], Docs) :-
-    atom_string(P, Path),
-    atom_string(F, Functor),
-    PI = F/Arity,
-    pi_head(PI, Head),
-    (   module_property(M, file(P)),
-        \+ predicate_property(M:Head, imported_from(_))
+sweep_documentation(PI0, Docs) :-
+    term_string(PI1, PI0),
+    (   PI1 = M:PI
     ->  true
-    ;   module_property(M0, file(P)),
-        predicate_property(M0:Head, imported_from(M))
-    ->  true
-    ;   M=user
+    ;   M=user, PI=PI1
     ),
     findall(Doc, sweep_documentation_(M, PI, Doc), Docs).
 
diff --git a/sweeprolog.el b/sweeprolog.el
index 5c58aea506..eaae52afae 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -157,6 +157,12 @@ inserted to the input history in 
`sweeprolog-top-level-mode' buffers."
   :type '(repeat string)
   :group 'sweeprolog)
 
+(defcustom sweeprolog-enable-eldoc t
+  "If non-nil, enable `eldoc' suport in `sweeprolog-mode' buffers."
+  :package-version '((sweeprolog "0.4.7"))
+  :type 'boolean
+  :group 'sweeprolog)
+
 (defcustom sweeprolog-enable-cursor-sensor t
   "If non-nil, enable `cursor-sensor-mode' in `sweeprolog-mode'.
 
@@ -2281,6 +2287,18 @@ variable at point, if any."
          (sweeprolog-highlight-variable (point) var)
        (sweeprolog-highlight-variable old)))))
 
+
+(defun sweeprolog-predicate-modes-doc (cb)
+  (when-let ((pi (sweeprolog-identifier-at-point)))
+    (sweeprolog-open-query "user"
+                           "sweep"
+                           "sweep_documentation"
+                           pi)
+    (let ((sol (sweeprolog-next-solution)))
+      (sweeprolog-close-query)
+      (when (sweeprolog-true-p sol)
+        (funcall cb (cadr sol) :thing pi :face 
font-lock-function-name-face)))))
+
 (defvar-local sweeprolog--timer nil)
 (defvar-local sweeprolog--colourise-buffer-duration 0.2)
 
@@ -2304,6 +2322,9 @@ variable at point, if any."
                 nil
                 nil
                 (font-lock-fontify-region-function . 
sweeprolog-colourise-some-terms)))
+  (when sweeprolog-enable-eldoc
+    (setq-local eldoc-documentation-strategy #'eldoc-documentation-default)
+    (add-hook 'eldoc-documentation-functions #'sweeprolog-predicate-modes-doc 
nil t))
   (let ((time (current-time)))
     (sweeprolog-colourise-buffer)
     (setq sweeprolog--colourise-buffer-duration (float-time (time-since 
time))))

Reply via email to