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:
Henrik Lissner 2020-10-29 15:01:04 -04:00
parent 57ef63d6ba
commit f02879dd04
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 43 additions and 26 deletions

View file

@ -1,12 +1,10 @@
;;; emacs/vc/config.el -*- lexical-binding: t; -*-
(when (fboundp 'bug-reference-mode)
(add-hook! '(text-mode-hook conf-mode-hook) #'bug-reference-mode)
(add-hook 'prog-mode-hook #'bug-reference-prog-mode)
(map! :map bug-reference-map
(map! :when (fboundp 'bug-reference-mode)
:map bug-reference-map
"RET" (cmds! (and (bound-and-true-p evil-mode)
(evil-normal-state-p))
#'bug-reference-push-button)))
#'bug-reference-push-button))
(when IS-WINDOWS

View file

@ -240,7 +240,7 @@ neither is available. These require ripgrep to be installed."
(defun +lookup-evil-goto-definition-backend-fn (_identifier)
"Uses `evil-goto-definition' to conduct a text search for IDENTIFIER in the
current buffer."
(and (fboundp 'evil-goto-definition)
(when (fboundp 'evil-goto-definition)
(ignore-errors
(cl-destructuring-bind (beg . end)
(bounds-of-thing-at-point 'symbol)
@ -249,6 +249,31 @@ 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-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
@ -318,22 +343,14 @@ for the current mode/buffer (if any), then falls back to the backends in
(defvar ffap-file-finder)
;;;###autoload
(defun +lookup/file (path)
(defun +lookup/file (&optional path)
"Figure out PATH from whatever is at point and open it.
Each function in `+lookup-file-functions' is tried until one changes the point
or the current buffer.
Otherwise, falls back on `find-file-at-point'."
(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)
(interactive)
(cond ((and path
buffer-file-name
(file-equal-p path buffer-file-name)

View file

@ -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
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'.
Stops at the first function to return non-nil or change the current
window/point.