Skip to content

Commit 3b49d33

Browse files
authored
Merge pull request #20 from dgutov/emacs-27-compat
Emacs 27 compatibility
2 parents 61864f8 + da4a8f3 commit 3b49d33

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ To enable then simply add the following to your init file:
2121

2222
```emacs-lisp
2323
(require 'ivy-xref)
24+
;; Emacs 27 only:
25+
(setq xref-show-definitions-function #'ivy-xref-show-defs)
26+
;; Necessary in Emacs <27. In Emacs 27 it will affect all xref-based commands
27+
;; other than xref-find-definitions (e.g. project-find-regexp):
2428
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs)
2529
```
2630

ivy-xref.el

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@
7777
(nreverse collection)))
7878

7979
;;;###autoload
80-
(defun ivy-xref-show-xrefs (xrefs alist)
81-
"Show the list of XREFS and ALIST via ivy."
80+
(defun ivy-xref-show-xrefs (fetcher alist)
81+
"Show the list of xrefs returned by FETCHER and ALIST via ivy."
8282
;; call the original xref--show-xref-buffer so we can be used with
8383
;; dired-do-find-regexp-and-replace etc which expects to use the normal xref
8484
;; results buffer but then bury it and delete the window containing it
8585
;; immediately since we don't want to see it - see
8686
;; https://github.com/alexmurray/ivy-xref/issues/2
87-
(let ((buffer (xref--show-xref-buffer xrefs alist)))
87+
(let* ((xrefs (if (functionp fetcher)
88+
;; Emacs 27
89+
(or (assoc-default 'fetched-xrefs alist)
90+
(funcall fetcher))
91+
fetcher))
92+
(buffer (xref--show-xref-buffer fetcher alist)))
8893
(quit-window)
8994
(let ((orig-buf (current-buffer))
9095
(orig-pos (point))
@@ -113,5 +118,17 @@
113118
;; return value
114119
buffer))
115120

121+
;;;###autoload
122+
(defun ivy-xref-show-defs (fetcher alist)
123+
(let ((xrefs (funcall fetcher)))
124+
(cond
125+
((not (cdr xrefs))
126+
(xref-pop-to-location (car xrefs)
127+
(assoc-default 'display-action alist)))
128+
(t
129+
(ivy-xref-show-xrefs fetcher
130+
(cons (cons 'fetched-xrefs xrefs)
131+
alist))))))
132+
116133
(provide 'ivy-xref)
117134
;;; ivy-xref.el ends here

0 commit comments

Comments
 (0)