feature/lookup: support multiple lookup functions & minor modes in :lookup

This commit is contained in:
Henrik Lissner 2018-04-22 23:55:49 -04:00
parent 97812583f0
commit 6ba9259735
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 44 additions and 43 deletions

View file

@ -25,17 +25,18 @@
((xref-backend-identifier-at-point (xref-find-backend)))))
(defun +lookup--jump-to (prop identifier)
(let ((fn (plist-get +lookup-current-functions prop))
(origin (point-marker)))
(setq fn (or (command-remapping fn) fn))
(condition-case e
(or (if (commandp fn)
(call-interactively fn)
(funcall fn identifier))
(/= (point-marker) origin))
('error
(message "%s" e)
nil))))
(cl-loop for fn in (plist-get '(:definition +lookup-definition-functions
:references +lookup-references-functions
:documentation +lookup-documentation-functions)
prop)
for fn = (or (command-remapping fn) fn)
if (condition-case e
(or (if (commandp fn)
(call-interactively fn)
(funcall fn identifier))
(/= (point-marker) origin))
('error (ignore (message "%s" e))))
return it))
;;
@ -60,14 +61,9 @@ Failing all that, it will give up with an error."
(cond ((null identifier)
(user-error "Nothing under point"))
((and (plist-member +lookup-current-functions :definition)
((and +lookup-definition-functions
(+lookup--jump-to :definition identifier)))
((ignore-errors (if other-window
(xref-find-definitions-other-window identifier)
(xref-find-definitions identifier))
t))
((and (require 'dumb-jump nil t)
;; dumb-jump doesn't tell us if it succeeded or not
(let ((old-fn (symbol-function 'dumb-jump-get-results))
@ -110,12 +106,9 @@ Failing all that, it will give up with an error."
Tries `xref-find-references' and falls back to rg/ag."
(interactive
(list (+lookup--symbol-or-region)))
(cond ((and (plist-member +lookup-current-functions :references)
(cond ((and +lookup-references-functions
(+lookup--jump-to :references identifier)))
((ignore-errors (xref-find-references identifier)
t))
((and identifier
(featurep 'counsel)
(let ((regex (rxt-quote-pcre identifier)))
@ -138,7 +131,7 @@ Goes down a list of possible backends:
4. Fall back to an online search, with `+lookup/online'"
(interactive
(list (+lookup--symbol-or-region)))
(cond ((and (plist-member +lookup-current-functions :documentation)
(cond ((and +lookup-documentation-functions
(+lookup--jump-to :documentation identifier)))
((and (featurep! :feature lookup +docsets)