]> git.eshelyaron.com Git - sweep.git/commitdiff
ADDED: on-the-fly documentation for predicates with eldoc
authorEshel Yaron <me@eshelyaron.com>
Sat, 1 Oct 2022 14:33:47 +0000 (17:33 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 1 Oct 2022 15:03:54 +0000 (18:03 +0300)
sweep.pl
sweeprolog.el

index b44526071160ccdf09ba7abfcba0b69cb0f1ae13..41b3618a1d2945afaacd4da437e8f548cd2306a9 100644 (file)
--- 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).
 
index 5c58aea506824e810ac29987a7c5b9316f1bc098..eaae52afae9b951b31ed3fd79ea99193a0fc2064 100644 (file)
@@ -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))))