Skip to content

Commit

Permalink
consult-xref: Let-bind this-command
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Jul 16, 2024
1 parent e1621f4 commit 41d382c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
37 changes: 17 additions & 20 deletions consult-xref.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,28 @@ See `xref-show-xrefs-function' for the description of the
FETCHER and ALIST arguments."
(let* ((consult-xref--fetcher fetcher)
(candidates (consult-xref--candidates))
(display (alist-get 'display-action alist)))
(display (alist-get 'display-action alist))
(this-command #'consult-xref))
(unless candidates
(user-error "No xref locations"))
(xref-pop-to-location
(if (cdr candidates)
(apply
#'consult--read
(consult--read
candidates
(append
(consult--customize-get #'consult-xref)
(list
:prompt "Go to xref: "
:history 'consult-xref--history
:require-match t
:sort nil
:category 'consult-xref
:group #'consult--prefix-group
:state
;; do not preview other frame
(when-let (fun (pcase-exhaustive display
('frame nil)
('window #'switch-to-buffer-other-window)
('nil #'switch-to-buffer)))
(consult-xref--preview fun))
:lookup (apply-partially #'consult--lookup-prop 'consult-xref))))
:prompt "Go to xref: "
:history 'consult-xref--history
:require-match t
:sort nil
:category 'consult-xref
:group #'consult--prefix-group
:state
;; do not preview other frame
(when-let (fun (pcase-exhaustive display
('frame nil)
('window #'switch-to-buffer-other-window)
('nil #'switch-to-buffer)))
(consult-xref--preview fun))
:lookup (apply-partially #'consult--lookup-prop 'consult-xref))
(get-text-property 0 'consult-xref (car candidates)))
display)))

Expand Down
6 changes: 3 additions & 3 deletions consult.el
Original file line number Diff line number Diff line change
Expand Up @@ -2995,10 +2995,10 @@ corresponding customization options."
(setq args (cddr args)))))
(macroexp-progn setter)))

(defun consult--customize-get (&optional cmd)
"Get configuration from `consult--customize-alist' for CMD."
(defun consult--customize-get ()
"Get configuration from `consult--customize-alist' for `this-command'."
(mapcar (lambda (x) (eval x 'lexical))
(alist-get (or cmd this-command) consult--customize-alist)))
(alist-get this-command consult--customize-alist)))

;;;; Commands

Expand Down

0 comments on commit 41d382c

Please sign in to comment.