Add ffap & bug-reference support to +lookup/file
And disable bug-reference-mode by default. It produces too many false positives, particularly in web modes where color hexes in strings and comments are very common. Now that bug-reference support is built into +lookup/file (on gf), users can use that instead.
This commit is contained in:
parent
57ef63d6ba
commit
f02879dd04
3 changed files with 43 additions and 26 deletions
|
@ -1,12 +1,10 @@
|
||||||
;;; emacs/vc/config.el -*- lexical-binding: t; -*-
|
;;; emacs/vc/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(when (fboundp 'bug-reference-mode)
|
(map! :when (fboundp 'bug-reference-mode)
|
||||||
(add-hook! '(text-mode-hook conf-mode-hook) #'bug-reference-mode)
|
:map bug-reference-map
|
||||||
(add-hook 'prog-mode-hook #'bug-reference-prog-mode)
|
|
||||||
(map! :map bug-reference-map
|
|
||||||
"RET" (cmds! (and (bound-and-true-p evil-mode)
|
"RET" (cmds! (and (bound-and-true-p evil-mode)
|
||||||
(evil-normal-state-p))
|
(evil-normal-state-p))
|
||||||
#'bug-reference-push-button)))
|
#'bug-reference-push-button))
|
||||||
|
|
||||||
|
|
||||||
(when IS-WINDOWS
|
(when IS-WINDOWS
|
||||||
|
|
|
@ -240,7 +240,7 @@ neither is available. These require ripgrep to be installed."
|
||||||
(defun +lookup-evil-goto-definition-backend-fn (_identifier)
|
(defun +lookup-evil-goto-definition-backend-fn (_identifier)
|
||||||
"Uses `evil-goto-definition' to conduct a text search for IDENTIFIER in the
|
"Uses `evil-goto-definition' to conduct a text search for IDENTIFIER in the
|
||||||
current buffer."
|
current buffer."
|
||||||
(and (fboundp 'evil-goto-definition)
|
(when (fboundp 'evil-goto-definition)
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(cl-destructuring-bind (beg . end)
|
(cl-destructuring-bind (beg . end)
|
||||||
(bounds-of-thing-at-point 'symbol)
|
(bounds-of-thing-at-point 'symbol)
|
||||||
|
@ -249,6 +249,31 @@ current buffer."
|
||||||
(not (and (>= pt beg)
|
(not (and (>= pt beg)
|
||||||
(< pt end))))))))
|
(< 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-bug-reference-backend-fn (_identifier)
|
||||||
|
"Searches for a bug reference in user/repo#123 or #123 format and opens it in
|
||||||
|
the browser."
|
||||||
|
(require 'bug-reference)
|
||||||
|
(let ((bug-reference-url-format bug-reference-url-format)
|
||||||
|
(bug-reference-bug-regexp bug-reference-bug-regexp)
|
||||||
|
(bug-reference-mode (derived-mode-p 'text-mode 'conf-mode))
|
||||||
|
(bug-reference-prog-mode (derived-mode-p 'prog-mode)))
|
||||||
|
(bug-reference--run-auto-setup)
|
||||||
|
(unwind-protect
|
||||||
|
(catch 'found
|
||||||
|
(bug-reference-fontify (line-beginning-position) (line-end-position))
|
||||||
|
(dolist (o (overlays-at (point)))
|
||||||
|
;; It should only be possible to have one URL overlay.
|
||||||
|
(when-let (url (overlay-get o 'bug-reference-url))
|
||||||
|
(browse-url url)
|
||||||
|
(throw 'found t))))
|
||||||
|
(bug-reference-unfontify (line-beginning-position) (line-end-position)))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Main commands
|
;;; Main commands
|
||||||
|
@ -318,22 +343,14 @@ for the current mode/buffer (if any), then falls back to the backends in
|
||||||
|
|
||||||
(defvar ffap-file-finder)
|
(defvar ffap-file-finder)
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +lookup/file (path)
|
(defun +lookup/file (&optional path)
|
||||||
"Figure out PATH from whatever is at point and open it.
|
"Figure out PATH from whatever is at point and open it.
|
||||||
|
|
||||||
Each function in `+lookup-file-functions' is tried until one changes the point
|
Each function in `+lookup-file-functions' is tried until one changes the point
|
||||||
or the current buffer.
|
or the current buffer.
|
||||||
|
|
||||||
Otherwise, falls back on `find-file-at-point'."
|
Otherwise, falls back on `find-file-at-point'."
|
||||||
(interactive
|
(interactive)
|
||||||
(progn
|
|
||||||
(require 'ffap)
|
|
||||||
(list
|
|
||||||
(or (ffap-guesser)
|
|
||||||
(ffap-read-file-or-url
|
|
||||||
(if ffap-url-regexp "Find file or URL: " "Find file: ")
|
|
||||||
(doom-thing-at-point-or-region))))))
|
|
||||||
(require 'ffap)
|
|
||||||
(cond ((and path
|
(cond ((and path
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
(file-equal-p path buffer-file-name)
|
(file-equal-p path buffer-file-name)
|
||||||
|
|
|
@ -97,7 +97,9 @@ If the argument is interactive (satisfies `commandp'), it is called with
|
||||||
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
||||||
this list.")
|
this list.")
|
||||||
|
|
||||||
(defvar +lookup-file-functions ()
|
(defvar +lookup-file-functions
|
||||||
|
'(+lookup-ffap-backend-fn
|
||||||
|
+lookup-bug-reference-backend-fn)
|
||||||
"Function for `+lookup/file' to try, before restoring to `find-file-at-point'.
|
"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
|
Stops at the first function to return non-nil or change the current
|
||||||
window/point.
|
window/point.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue