Enhance FFAP lookup backend
gf (+lookup/file) has been changed to: + Use the active selection instead of the filename-at-point when searching for a file (as requested in #4942). + Pre-fill the FFAP prompt with the thing at point if no obvious filepath can be guessed from it (via ffap-alist). + Offer to search the current project for the thing-at-point (if counsel-file-jump is available). + Fall back to a standard ffap prompt if all else fails. I've also reversed te order of file lookup backends so that our FFAP backend is treated as a never-failing last resort (also because the bug-reference backend is known to fail gracefully, so we can trust it to run first). Closes #4942
This commit is contained in:
parent
3a4024e790
commit
259cf83ef1
2 changed files with 22 additions and 15 deletions
|
@ -258,11 +258,25 @@ current buffer."
|
|||
(not (and (>= pt beg)
|
||||
(< pt end))))))))
|
||||
|
||||
(defun +lookup-ffap-backend-fn (_identifier)
|
||||
"Uses `find-file-at-point' to read file at point."
|
||||
(require 'ffap)
|
||||
(when (ffap-guesser)
|
||||
(find-file-at-point)
|
||||
(defun +lookup-ffap-backend-fn (identifier)
|
||||
"Tries to locate the file at point (or in active selection).
|
||||
Uses find-in-project functionality (provided by ivy, helm, or project),
|
||||
otherwise falling back to ffap.el (find-file-at-point)."
|
||||
(let ((guess
|
||||
(cond (identifier)
|
||||
((doom-region-active-p)
|
||||
(buffer-substring-no-properties
|
||||
(doom-region-beginning)
|
||||
(doom-region-end)))
|
||||
((if (require 'ffap) (ffap-guesser)))
|
||||
((thing-at-point 'filename t)))))
|
||||
(cond ((and (stringp guess)
|
||||
(file-exists-p guess))
|
||||
(find-file-at-point guess))
|
||||
((and (featurep! :completion ivy)
|
||||
(doom-project-p))
|
||||
(counsel-file-jump guess (doom-project-root)))
|
||||
((find-file-at-point (ffap-prompter guess))))
|
||||
t))
|
||||
|
||||
(defun +lookup-bug-reference-backend-fn (_identifier)
|
||||
|
@ -351,7 +365,6 @@ for the current mode/buffer (if any), then falls back to the backends in
|
|||
(cond ((+lookup--jump-to :documentation identifier #'pop-to-buffer arg))
|
||||
((user-error "Couldn't find documentation for %S" identifier))))
|
||||
|
||||
(defvar ffap-file-finder)
|
||||
;;;###autoload
|
||||
(defun +lookup/file (&optional path)
|
||||
"Figure out PATH from whatever is at point and open it.
|
||||
|
@ -368,13 +381,7 @@ Otherwise, falls back on `find-file-at-point'."
|
|||
|
||||
((+lookup--jump-to :file path))
|
||||
|
||||
((stringp path) (find-file-at-point path))
|
||||
|
||||
((featurep! :completion ivy)
|
||||
(counsel-file-jump (thing-at-point 'filename t)
|
||||
(doom-project-root)))
|
||||
|
||||
((ffap-prompter (thing-at-point 'filename t)))))
|
||||
((user-error "Couldn't find any files here"))))
|
||||
|
||||
|
||||
;;
|
||||
|
|
|
@ -99,8 +99,8 @@ argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|||
this list.")
|
||||
|
||||
(defvar +lookup-file-functions
|
||||
'(+lookup-ffap-backend-fn
|
||||
+lookup-bug-reference-backend-fn)
|
||||
'(+lookup-bug-reference-backend-fn
|
||||
+lookup-ffap-backend-fn)
|
||||
"Function for `+lookup/file' to try, before restoring to `find-file-at-point'.
|
||||
Stops at the first function to return non-nil or change the current
|
||||
window/point.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue