bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66668: [PATCH] Teach ffap to look for paths under the root of projec


From: Spencer Baugh
Subject: bug#66668: [PATCH] Teach ffap to look for paths under the root of project
Date: Wed, 25 Oct 2023 11:08:12 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: Dmitry Gutov <dmitry@gutov.dev>
>> From: Spencer Baugh <sbaugh@janestreet.com>
>> Date: Sat, 21 Oct 2023 14:37:45 -0400
>> 
>> Subject: [PATCH] Teach ffap to look for paths under the root of project
>
> Please don't use "path" when you mean "file name".  The GNU Coding
> Standards frown on such uses of "path".

Oops, fixed.

(Also fixed a byte-compiler warning from not declaring project-root)

>From 4423e8eb9b54652c114bb9d6b6b3b873a15a24a9 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Sat, 21 Oct 2023 14:35:53 -0400
Subject: [PATCH] Teach ffap to look for relative file names under project-root

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 | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lisp/ffap.el b/lisp/ffap.el
index 2c99f88d505..0c9ff8617d6 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -734,6 +734,7 @@ ffap-locate-file
 (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]
@@ -797,6 +798,11 @@ ffap-completable
         (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)
-- 
2.39.3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]