]> git.eshelyaron.com Git - emacs.git/commitdiff
Add imenu support to xref
authorDamien Cassou <damien@cassou.me>
Fri, 23 Aug 2019 04:30:46 +0000 (06:30 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 23 Aug 2019 04:30:46 +0000 (06:30 +0200)
* lisp/progmodes/xref.el (xref--imenu-prev-index-position)
(xref--imenu-extract-index-name): Add functions to get imenu support.
(xref--xref-buffer-mode): Set imenu variables to the new functions.
* etc/NEWS: Add corresponding entry (bug#36974).

etc/NEWS
lisp/progmodes/xref.el

index cd47464039291ba6af4a193ef2bcaa60167fc139..60327e92d2cc20491e9a8ef1c28de90f51fdf5e5 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1849,6 +1849,11 @@ and 'gravatar-force-default'.
 *** The built-in ada-mode is now deleted.  The Gnu ELPA package is a
 good replacement, even in very large source files.
 
+** xref
+
+---
+*** Imenu support has been added to 'xref--xref-buffer-mode'.
+
 \f
 * New Modes and Packages in Emacs 27.1
 
index ae35766ecdc40fa879dd5f510465427394f4324e..eef2ca643f6426e80e6781698f190de3bfc7500d 100644 (file)
@@ -728,7 +728,11 @@ references displayed in the current *xref* buffer."
   "Mode for displaying cross-references."
   (setq buffer-read-only t)
   (setq next-error-function #'xref--next-error-function)
-  (setq next-error-last-buffer (current-buffer)))
+  (setq next-error-last-buffer (current-buffer))
+  (setq imenu-prev-index-position-function
+        #'xref--imenu-prev-index-position)
+  (setq imenu-extract-index-name-function
+        #'xref--imenu-extract-index-name))
 
 (defvar xref--transient-buffer-mode-map
   (let ((map (make-sparse-keymap)))
@@ -740,6 +744,22 @@ references displayed in the current *xref* buffer."
   xref--xref-buffer-mode
   "XREF Transient")
 
+(defun xref--imenu-prev-index-position ()
+  "Move point to previous line in `xref' buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+  (if (bobp)
+      nil
+    (xref--search-property 'xref-group t)))
+
+(defun xref--imenu-extract-index-name ()
+  "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'.  Point should be at the
+beginning of the line."
+  (buffer-substring-no-properties (line-beginning-position)
+                                  (line-end-position)))
+
 (defun xref--next-error-function (n reset?)
   (when reset?
     (goto-char (point-min)))
@@ -789,7 +809,8 @@ GROUP is a string for decoration purposes and XREF is an
            for line-format = (and max-line-width
                                   (format "%%%dd: " max-line-width))
            do
-           (xref--insert-propertized '(face xref-file-header) group "\n")
+           (xref--insert-propertized '(face xref-file-header 'xref-group t)
+                                     group "\n")
            (cl-loop for (xref . more2) on xrefs do
                     (with-slots (summary location) xref
                       (let* ((line (xref-location-line location))