]> git.eshelyaron.com Git - sweep.git/commitdiff
ADDED: support imenu in sweep-mode buffers
authorEshel Yaron <me@eshelyaron.com>
Sun, 25 Sep 2022 14:35:13 +0000 (17:35 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 25 Sep 2022 14:35:13 +0000 (17:35 +0300)
sweep.el
sweep.pl

index 8297f5262bb2f7a63cc534738603d787f2eee3b7..7ba846beb14d6993d8fa0a510abb02ad4bab8d74 100644 (file)
--- 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)
index a161694a6b01a73ec1c42b49fbb96f673bfe8f09..de9be3e20e80202e9882bc3c13c3808d9979691f 100644 (file)
--- 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).