branch: externals/embark
commit fc3b1650d2b6b99cd8cc5cfbe774c5e3201b6bab
Author: Omar Antolín <[email protected]>
Commit: Omar Antolín <[email protected]>
Exporter for consult-xref
Initial implementation of an exporter for consult-xref, see
minad/consult#557.
---
embark-consult.el | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/embark-consult.el b/embark-consult.el
index d4de0e0992..02fdfccd90 100644
--- a/embark-consult.el
+++ b/embark-consult.el
@@ -171,8 +171,8 @@ This function is meant to be added to
`embark-collect-mode-hook'."
(defvar wgrep-header/footer-parser)
(declare-function wgrep-setup "ext:wgrep")
-(embark-define-keymap embark-consult-export-grep-map
- "A keymap for Embark Export grep-mode buffers."
+(embark-define-keymap embark-consult-revert-map
+ "A keymap with a binding for revert-buffer."
:parent nil
("g" revert-buffer))
@@ -187,7 +187,7 @@ This function is meant to be added to
`embark-collect-mode-hook'."
;; Set up keymap before possible wgrep-setup, so that wgrep
;; restores our binding too when the user finishes editing.
(use-local-map (make-composed-keymap
- embark-consult-export-grep-map
+ embark-consult-revert-map
(current-local-map)))
(setq-local wgrep-header/footer-parser #'ignore)
(when (fboundp 'wgrep-setup) (wgrep-setup)))
@@ -212,6 +212,25 @@ This function is meant to be added to
`embark-collect-mode-hook'."
(setf (alist-get 'consult-grep embark-exporters-alist)
#'embark-consult-export-grep)
+;;; Support for consult-xref
+
+(declare-function xref--show-xref-buffer "ext:xref")
+
+(defun embark-consult-export-xref (items)
+ "Create an xref buffer listing ITEMS."
+ (let ((xref-items (mapcar (lambda (item)
+ (get-text-property 0 'consult-xref item))
+ items)))
+ (set-buffer
+ (xref--show-xref-buffer
+ (lambda () xref-items)
+ `((window . ,(embark--target-window))
+ (auto-jump . ,xref-auto-jump-to-first-xref)
+ (display-action))))))
+
+(setf (alist-get 'consult-xref embark-exporters-alist)
+ #'embark-consult-export-xref)
+
;;; Support for consult-find and consult-locate
(setf (alist-get '(file . consult-find) embark-default-action-overrides)