tools/lookup: add prefix arg to lookup commands
The prefix arg causes +lookup/{definition,references,documentation} to prompt you for which lookup backend to use.
This commit is contained in:
parent
1f88efeb82
commit
ae8aa26c33
1 changed files with 28 additions and 19 deletions
|
@ -122,18 +122,24 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
|
||||||
(message "Lookup handler %S: %s" handler e)
|
(message "Lookup handler %S: %s" handler e)
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(defun +lookup--jump-to (prop identifier &optional display-fn)
|
(defun +lookup--jump-to (prop identifier &optional display-fn arg)
|
||||||
(let* ((origin (point-marker))
|
(let* ((origin (point-marker))
|
||||||
|
(handlers (plist-get (list :definition '+lookup-definition-functions
|
||||||
|
:references '+lookup-references-functions
|
||||||
|
:documentation '+lookup-documentation-functions
|
||||||
|
:file '+lookup-file-functions)
|
||||||
|
prop))
|
||||||
(result
|
(result
|
||||||
(run-hook-wrapped
|
(if arg
|
||||||
(plist-get (list :definition '+lookup-definition-functions
|
(if-let*
|
||||||
:references '+lookup-references-functions
|
((handler (intern-soft
|
||||||
:documentation '+lookup-documentation-functions
|
(completing-read "Select lookup handler: "
|
||||||
:file '+lookup-file-functions)
|
(remq t (append (symbol-value handlers)
|
||||||
prop)
|
(default-value handlers)))
|
||||||
#'+lookup--run-handlers
|
nil t))))
|
||||||
identifier
|
(+lookup--run-handlers handler identifier origin)
|
||||||
origin)))
|
(user-error "No lookup handler selected"))
|
||||||
|
(run-hook-wrapped handlers #'+lookup--run-handlers identifier origin))))
|
||||||
(when (cond ((null result)
|
(when (cond ((null result)
|
||||||
(message "No lookup handler could find %S" identifier)
|
(message "No lookup handler could find %S" identifier)
|
||||||
nil)
|
nil)
|
||||||
|
@ -225,39 +231,42 @@ current buffer."
|
||||||
;;; Main commands
|
;;; Main commands
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +lookup/definition (identifier)
|
(defun +lookup/definition (identifier &optional arg)
|
||||||
"Jump to the definition of IDENTIFIER (defaults to the symbol at point).
|
"Jump to the definition of IDENTIFIER (defaults to the symbol at point).
|
||||||
|
|
||||||
Each function in `+lookup-definition-functions' is tried until one changes the
|
Each function in `+lookup-definition-functions' is tried until one changes the
|
||||||
point or current buffer. Falls back to dumb-jump, naive
|
point or current buffer. Falls back to dumb-jump, naive
|
||||||
ripgrep/the_silver_searcher text search, then `evil-goto-definition' if
|
ripgrep/the_silver_searcher text search, then `evil-goto-definition' if
|
||||||
evil-mode is active."
|
evil-mode is active."
|
||||||
(interactive (list (+lookup-symbol-or-region)))
|
(interactive (list (+lookup-symbol-or-region)
|
||||||
|
current-prefix-arg))
|
||||||
(cond ((null identifier) (user-error "Nothing under point"))
|
(cond ((null identifier) (user-error "Nothing under point"))
|
||||||
((+lookup--jump-to :definition identifier))
|
((+lookup--jump-to :definition identifier nil arg))
|
||||||
((error "Couldn't find the definition of %S" identifier))))
|
((error "Couldn't find the definition of %S" identifier))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +lookup/references (identifier)
|
(defun +lookup/references (identifier &optional arg)
|
||||||
"Show a list of usages of IDENTIFIER (defaults to the symbol at point)
|
"Show a list of usages of IDENTIFIER (defaults to the symbol at point)
|
||||||
|
|
||||||
Tries each function in `+lookup-references-functions' until one changes the
|
Tries each function in `+lookup-references-functions' until one changes the
|
||||||
point and/or current buffer. Falls back to a naive ripgrep/the_silver_searcher
|
point and/or current buffer. Falls back to a naive ripgrep/the_silver_searcher
|
||||||
search otherwise."
|
search otherwise."
|
||||||
(interactive (list (+lookup-symbol-or-region)))
|
(interactive (list (+lookup-symbol-or-region)
|
||||||
|
current-prefix-arg))
|
||||||
(cond ((null identifier) (user-error "Nothing under point"))
|
(cond ((null identifier) (user-error "Nothing under point"))
|
||||||
((+lookup--jump-to :references identifier))
|
((+lookup--jump-to :references identifier nil arg))
|
||||||
((error "Couldn't find references of %S" identifier))))
|
((error "Couldn't find references of %S" identifier))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +lookup/documentation (identifier)
|
(defun +lookup/documentation (identifier &optional arg)
|
||||||
"Show documentation for IDENTIFIER (defaults to symbol at point or selection.
|
"Show documentation for IDENTIFIER (defaults to symbol at point or selection.
|
||||||
|
|
||||||
First attempts the :documentation handler specified with `set-lookup-handlers!'
|
First attempts the :documentation handler specified with `set-lookup-handlers!'
|
||||||
for the current mode/buffer (if any), then falls back to the backends in
|
for the current mode/buffer (if any), then falls back to the backends in
|
||||||
`+lookup-documentation-functions'."
|
`+lookup-documentation-functions'."
|
||||||
(interactive (list (+lookup-symbol-or-region)))
|
(interactive (list (+lookup-symbol-or-region)
|
||||||
(cond ((+lookup--jump-to :documentation identifier #'pop-to-buffer))
|
current-prefix-arg))
|
||||||
|
(cond ((+lookup--jump-to :documentation identifier #'pop-to-buffer arg))
|
||||||
((user-error "Couldn't find documentation for %S" identifier))))
|
((user-error "Couldn't find documentation for %S" identifier))))
|
||||||
|
|
||||||
(defvar ffap-file-finder)
|
(defvar ffap-file-finder)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue