From: Spencer Baugh <sbaugh@janestreet.com>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: sbaugh@catern.com, Juri Linkov <juri@linkov.net>, 63829@debbugs.gnu.org
Subject: bug#63829: 29.0.90; project-find-file's future history breaks with common-parent-directory
Date: Thu, 17 Aug 2023 16:12:33 -0400 [thread overview]
Message-ID: <ier8ra9pgwe.fsf@janestreet.com> (raw)
In-Reply-To: <ierbkf5pibo.fsf@janestreet.com> (Spencer Baugh's message of "Thu, 17 Aug 2023 15:41:47 -0400")
[-- Attachment #1: Type: text/plain, Size: 279 bytes --]
Spencer Baugh <sbaugh@janestreet.com> writes:
> In a subsequent mail I'll send a patch for the "future history"
> behavior of project-find-dir too. (yet to be written)
Here is that. Seems like a straightforward generalization, and
something that a user would expect to work.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-current-file-name-for-more-other-project-future-.patch --]
[-- Type: text/x-patch, Size: 4913 bytes --]
From 48880a795f75d1126a0f235bf57f00f478ee90a0 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Thu, 17 Aug 2023 16:11:01 -0400
Subject: [PATCH] Use current file name for more "other project" future history
In commit f38bcf37dc47ce172c985d1c621df3583eaad46c we supported using
the current buffer's file name as future history for project-find-file
even when switching to another project with project-switch-project.
Make this work for project-find-dir and project-or-external-find-file
too.
* lisp/progmodes/project.el (project--find-default-from): Add.
(project-find-file): Use project--find-default-from with
buffer-file-name.
(project-or-external-find-file): Use project--find-default-from with
buffer-file-name.
(project-find-dir): Use project--find-default-from with
default-directory.
---
lisp/progmodes/project.el | 45 +++++++++++++++++++++++++++------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index e0f1f995ff2..e0d05d45a55 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -989,6 +989,23 @@ project--read-regexp
(read-regexp "Find regexp" (and sym (regexp-quote sym))
project-regexp-history-variable)))
+(defun project--find-default-from (filename project)
+ "Ensure FILENAME is in PROJECT.
+
+Usually, just return FILENAME. But if
+`project-current-directory-override' is set, FILENAME is probably
+relative to that project; adjust it to be relative to PROJECT instead.
+
+This supports using a relative file name from the current buffer
+when switching projects with `project-switch-project' and then
+using a command like `project-find-file'."
+ (if-let (filename-proj (and project-current-directory-override
+ (project-current nil default-directory)))
+ ;; file-name-concat requires Emacs 28+
+ (concat (file-name-as-directory (project-root project))
+ (file-relative-name filename (project-root filename-proj)))
+ filename))
+
;;;###autoload
(defun project-find-file (&optional include-all)
"Visit a file (with completion) in the current project.
@@ -1006,16 +1023,7 @@ project-find-file
(dirs (list root)))
(project-find-file-in
(or (thing-at-point 'filename)
- (and buffer-file-name
- (if-let (buffer-proj (and project-current-directory-override
- (project-current nil default-directory)))
- ;; Allow using the relative file name of the current
- ;; buffer in "other project" as well.
- (let ((buffer-root (project-root buffer-proj)))
- ;; file-name-concat requires Emacs 28+
- (concat (file-name-as-directory root)
- (file-relative-name buffer-file-name buffer-root)))
- buffer-file-name)))
+ (and buffer-file-name (project--find-default-from buffer-file-name pr)))
dirs pr include-all)))
;;;###autoload
@@ -1023,7 +1031,8 @@ project-or-external-find-file
"Visit a file (with completion) in the current project or external roots.
The filename at point (determined by `thing-at-point'), if any,
-is available as part of \"future history\".
+is available as part of \"future history\". If none, the current
+buffer's file name is used.
If INCLUDE-ALL is non-nil, or with prefix argument when called
interactively, include all files under the project root, except
@@ -1033,7 +1042,10 @@ project-or-external-find-file
(dirs (cons
(project-root pr)
(project-external-roots pr))))
- (project-find-file-in (thing-at-point 'filename) dirs pr include-all)))
+ (project-find-file-in
+ (or (thing-at-point 'filename)
+ (and buffer-file-name (project--find-default-from buffer-file-name pr)))
+ dirs pr include-all)))
(defcustom project-read-file-name-function #'project--read-file-cpd-relative
"Function to call to read a file name from a list.
@@ -1185,7 +1197,10 @@ project--completing-read-strict
;;;###autoload
(defun project-find-dir ()
- "Start Dired in a directory inside the current project."
+ "Start Dired in a directory inside the current project.
+
+The current buffer's `default-directory' is available as part of
+\"future history\"."
(interactive)
(let* ((project (project-current t))
(all-files (project-files project))
@@ -1200,7 +1215,9 @@ project-find-dir
project "Dired"
;; Some completion UIs show duplicates.
(delete-dups all-dirs)
- nil 'file-name-history)))
+ nil 'file-name-history
+ (and default-directory
+ (project--find-default-from default-directory project)))))
(dired dir)))
;;;###autoload
--
2.39.3
next prev parent reply other threads:[~2023-08-17 20:12 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-01 22:32 bug#63829: 29.0.90; project-find-file's future history breaks with common-parent-directory Spencer Baugh
2023-06-02 6:47 ` Eli Zaretskii
2023-06-03 12:19 ` Dmitry Gutov
2023-06-03 12:48 ` Eli Zaretskii
2023-06-03 13:48 ` Dmitry Gutov
2023-06-03 2:30 ` Dmitry Gutov
2023-06-03 11:00 ` Spencer Baugh
2023-06-04 16:36 ` Juri Linkov
2023-06-06 1:40 ` Dmitry Gutov
2023-06-06 15:55 ` Spencer Baugh
2023-08-10 12:02 ` sbaugh
2023-08-12 1:23 ` Dmitry Gutov
2023-08-14 20:12 ` Spencer Baugh
2023-08-14 22:47 ` sbaugh
2023-08-16 1:49 ` Dmitry Gutov
2023-08-16 2:57 ` sbaugh
2023-08-17 2:14 ` Dmitry Gutov
2023-08-17 19:41 ` Spencer Baugh
2023-08-17 20:12 ` Spencer Baugh [this message]
2023-08-18 20:57 ` Spencer Baugh
2023-08-19 2:14 ` Dmitry Gutov
2023-08-20 17:23 ` Juri Linkov
2023-08-20 17:16 ` Juri Linkov
2023-08-21 1:15 ` Dmitry Gutov
2023-08-23 2:13 ` Dmitry Gutov
2023-08-19 2:08 ` Dmitry Gutov
2023-08-19 12:00 ` sbaugh
2023-08-21 1:51 ` Dmitry Gutov
2023-08-20 17:20 ` Juri Linkov
2023-08-21 1:43 ` Dmitry Gutov
2023-08-21 7:06 ` Juri Linkov
2023-08-23 0:37 ` Dmitry Gutov
2023-08-23 2:26 ` Dmitry Gutov
2023-08-23 17:52 ` Juri Linkov
2023-08-23 18:25 ` Dmitry Gutov
2023-08-20 17:13 ` Juri Linkov
2023-08-21 1:17 ` Dmitry Gutov
2023-08-21 6:58 ` Juri Linkov
2023-08-23 0:27 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ier8ra9pgwe.fsf@janestreet.com \
--to=sbaugh@janestreet.com \
--cc=63829@debbugs.gnu.org \
--cc=dmitry@gutov.dev \
--cc=juri@linkov.net \
--cc=sbaugh@catern.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).