From: Damien Cassou Date: Fri, 23 Aug 2019 04:30:46 +0000 (+0200) Subject: Add imenu support to xref X-Git-Tag: emacs-27.0.90~1328^2~115 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1071dfe18175ecf48d98ea9d3fd1468a7a5e9568;p=emacs.git Add imenu support to xref * 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). --- diff --git a/etc/NEWS b/etc/NEWS index cd474640392..60327e92d2c 100644 --- 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'. + * New Modes and Packages in Emacs 27.1 diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index ae35766ecdc..eef2ca643f6 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -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))