emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sweeprolog c6066eabb9 144/166: ADDED: support imenu in swe


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog c6066eabb9 144/166: ADDED: support imenu in sweep-mode buffers
Date: Fri, 30 Sep 2022 04:59:33 -0400 (EDT)

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

    ADDED: support imenu in sweep-mode buffers
---
 sweep.el | 17 +++++++++++++++++
 sweep.pl | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/sweep.el b/sweep.el
index 8297f5262b..7ba846beb1 100644
--- a/sweep.el
+++ b/sweep.el
@@ -2000,6 +2000,22 @@ Interactively, POINT is set to the current point."
                             (xref-make-file-location path line 0))))
              matches)))
 
+(defun sweep-create-index-function ()
+  (sweep-open-query "user"
+                    "sweep"
+                    "sweep_imenu_index"
+                    (buffer-file-name))
+  (let ((sol (sweep-next-solution)))
+    (sweep-close-query)
+    (when (sweep-true-p sol)
+      (seq-map (lambda (entry)
+                 (let ((car (car entry))
+                       (line (cdr entry)))
+                   (goto-char (point-min))
+                   (forward-line (1- line))
+                   (cons car (line-beginning-position))))
+               (cdr sol)))))
+
 (defvar-local sweep--timer nil)
 (defvar-local sweep--colourise-buffer-duration 0.2)
 
@@ -2010,6 +2026,7 @@ Interactively, POINT is set to the current point."
   (setq-local comment-start "%")
   (setq-local comment-start-skip "\\(?:/\\*+ *\\|%+ *\\)")
   (setq-local parens-require-spaces nil)
+  (setq-local imenu-create-index-function #'sweep-create-index-function)
   (setq-local beginning-of-defun-function #'sweep-beginning-of-top-term)
   (setq-local end-of-defun-function #'sweep-end-of-top-term)
   (setq-local forward-sexp-function #'sweep-forward-sexp-function)
diff --git a/sweep.pl b/sweep.pl
index a161694a6b..de9be3e20e 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -53,6 +53,7 @@
             sweep_pack_install/2,
             sweep_prefix_ops/2,
             sweep_op_info/2,
+            sweep_imenu_index/2,
             sweep_module_path/2
           ]).
 
@@ -727,3 +728,13 @@ with_buffer_stream(Stream, String, Goal) :-
                        ( close(Stream),
                          free_memory_file(H)
                        )).
+
+sweep_imenu_index(Path, Index) :-
+    atom_string(Atom, Path),
+    findall([String|L],
+            ( xref_defined(Atom, D, H),
+              xref_definition_line(H, L),
+              pi_head(PI, D),
+              term_string(PI, String)
+            ),
+            Index).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]