diff options
| author | Damien Cassou | 2019-08-23 06:30:46 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-08-23 06:30:46 +0200 |
| commit | 1071dfe18175ecf48d98ea9d3fd1468a7a5e9568 (patch) | |
| tree | 9c34aa6a355db545ed43cdb98c6587ba429d3092 | |
| parent | fbbc257190d115dc76e1a8cf4e4992d52d7f55b9 (diff) | |
| download | emacs-1071dfe18175ecf48d98ea9d3fd1468a7a5e9568.tar.gz emacs-1071dfe18175ecf48d98ea9d3fd1468a7a5e9568.zip | |
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).
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 25 |
2 files changed, 28 insertions, 2 deletions
| @@ -1849,6 +1849,11 @@ and 'gravatar-force-default'. | |||
| 1849 | *** The built-in ada-mode is now deleted. The Gnu ELPA package is a | 1849 | *** The built-in ada-mode is now deleted. The Gnu ELPA package is a |
| 1850 | good replacement, even in very large source files. | 1850 | good replacement, even in very large source files. |
| 1851 | 1851 | ||
| 1852 | ** xref | ||
| 1853 | |||
| 1854 | --- | ||
| 1855 | *** Imenu support has been added to 'xref--xref-buffer-mode'. | ||
| 1856 | |||
| 1852 | 1857 | ||
| 1853 | * New Modes and Packages in Emacs 27.1 | 1858 | * New Modes and Packages in Emacs 27.1 |
| 1854 | 1859 | ||
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." | |||
| 728 | "Mode for displaying cross-references." | 728 | "Mode for displaying cross-references." |
| 729 | (setq buffer-read-only t) | 729 | (setq buffer-read-only t) |
| 730 | (setq next-error-function #'xref--next-error-function) | 730 | (setq next-error-function #'xref--next-error-function) |
| 731 | (setq next-error-last-buffer (current-buffer))) | 731 | (setq next-error-last-buffer (current-buffer)) |
| 732 | (setq imenu-prev-index-position-function | ||
| 733 | #'xref--imenu-prev-index-position) | ||
| 734 | (setq imenu-extract-index-name-function | ||
| 735 | #'xref--imenu-extract-index-name)) | ||
| 732 | 736 | ||
| 733 | (defvar xref--transient-buffer-mode-map | 737 | (defvar xref--transient-buffer-mode-map |
| 734 | (let ((map (make-sparse-keymap))) | 738 | (let ((map (make-sparse-keymap))) |
| @@ -740,6 +744,22 @@ references displayed in the current *xref* buffer." | |||
| 740 | xref--xref-buffer-mode | 744 | xref--xref-buffer-mode |
| 741 | "XREF Transient") | 745 | "XREF Transient") |
| 742 | 746 | ||
| 747 | (defun xref--imenu-prev-index-position () | ||
| 748 | "Move point to previous line in `xref' buffer. | ||
| 749 | This function is used as a value for | ||
| 750 | `imenu-prev-index-position-function'." | ||
| 751 | (if (bobp) | ||
| 752 | nil | ||
| 753 | (xref--search-property 'xref-group t))) | ||
| 754 | |||
| 755 | (defun xref--imenu-extract-index-name () | ||
| 756 | "Return imenu name for line at point. | ||
| 757 | This function is used as a value for | ||
| 758 | `imenu-extract-index-name-function'. Point should be at the | ||
| 759 | beginning of the line." | ||
| 760 | (buffer-substring-no-properties (line-beginning-position) | ||
| 761 | (line-end-position))) | ||
| 762 | |||
| 743 | (defun xref--next-error-function (n reset?) | 763 | (defun xref--next-error-function (n reset?) |
| 744 | (when reset? | 764 | (when reset? |
| 745 | (goto-char (point-min))) | 765 | (goto-char (point-min))) |
| @@ -789,7 +809,8 @@ GROUP is a string for decoration purposes and XREF is an | |||
| 789 | for line-format = (and max-line-width | 809 | for line-format = (and max-line-width |
| 790 | (format "%%%dd: " max-line-width)) | 810 | (format "%%%dd: " max-line-width)) |
| 791 | do | 811 | do |
| 792 | (xref--insert-propertized '(face xref-file-header) group "\n") | 812 | (xref--insert-propertized '(face xref-file-header 'xref-group t) |
| 813 | group "\n") | ||
| 793 | (cl-loop for (xref . more2) on xrefs do | 814 | (cl-loop for (xref . more2) on xrefs do |
| 794 | (with-slots (summary location) xref | 815 | (with-slots (summary location) xref |
| 795 | (let* ((line (xref-location-line location)) | 816 | (let* ((line (xref-location-line location)) |