]> git.eshelyaron.com Git - emacs.git/commitdiff
Teach ffap to look for relative file names under project-root
authorSpencer Baugh <sbaugh@janestreet.com>
Sat, 21 Oct 2023 18:35:53 +0000 (14:35 -0400)
committerDmitry Gutov <dmitry@gutov.dev>
Mon, 30 Oct 2023 00:57:33 +0000 (02:57 +0200)
Now file-name-at-point-functions, which runs
ffap-guess-file-name-at-point, will pick up on a file name at point if
that file name is a relative file name which exists when looked up
from the root of the project.

For example, in test/lisp/progmodes/eglot-tests.el there is the string
lisp/progmodes/eglot.el; if you put point on that and C-x C-f,
lisp/progmodes/eglot.el under the root of the Emacs repo will now be
part of future history.

* lisp/ffap.el (ffap-alist): Add entry for ffap-in-project.
(ffap-in-project): Add. (bug#66668)

lisp/ffap.el

index 942e218bf239204b5374065ff667ea7a41496631..530e3da182e482e9adfa785c74974bede928b2a7 100644 (file)
@@ -730,6 +730,7 @@ This uses `ffap-file-exists-string', which may try adding suffixes from
 (defvar ffap-alist
   '(
     ("" . ffap-completable)            ; completion, slow on some systems
+    ("" . ffap-in-project)             ; maybe in the root of the project
     ("\\.info\\'" . ffap-info)         ; gzip.info
     ("\\`info/" . ffap-info-2)         ; info/emacs
     ("\\`[-[:lower:]]+\\'" . ffap-info-3) ; (emacs)Top [only in the parentheses]
@@ -793,6 +794,11 @@ to extract substrings.")
         (cmp (file-name-completion (file-name-nondirectory name) dir)))
     (and cmp (concat dir cmp))))
 
+(declare-function project-root "project" (project))
+(defun ffap-in-project (name)
+  (when-let (project (project-current))
+    (file-name-concat (project-root project) name)))
+
 (defun ffap-home (name) (ffap-locate-file name t '("~")))
 
 (defun ffap-info (name)