From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs 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 Message-ID: References: <16b64d95-35e9-ef94-2c54-17b670111f0f@gutov.dev> <86h6rnw7gm.fsf@mail.linkov.net> <3e404df1-b3a9-f9e3-4270-f42df8b704c7@gutov.dev> <87a5uti6mo.fsf@catern.com> <73a695f3-7c6a-0e50-41dd-61f8269f6ecf@gutov.dev> <875y5fitiq.fsf@catern.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33558"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: sbaugh@catern.com, Juri Linkov , 63829@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 17 22:13:31 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qWjN5-0008Wh-5x for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Aug 2023 22:13:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWjMg-0001jc-JJ; Thu, 17 Aug 2023 16:13:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWjMc-0001jG-9R for bug-gnu-emacs@gnu.org; Thu, 17 Aug 2023 16:13:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWjMc-00034l-1N for bug-gnu-emacs@gnu.org; Thu, 17 Aug 2023 16:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qWjMb-0006Cu-N8 for bug-gnu-emacs@gnu.org; Thu, 17 Aug 2023 16:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 17 Aug 2023 20:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63829 X-GNU-PR-Package: emacs Original-Received: via spool by 63829-submit@debbugs.gnu.org id=B63829.169230316423836 (code B ref 63829); Thu, 17 Aug 2023 20:13:01 +0000 Original-Received: (at 63829) by debbugs.gnu.org; 17 Aug 2023 20:12:44 +0000 Original-Received: from localhost ([127.0.0.1]:45671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWjMJ-0006CN-OO for submit@debbugs.gnu.org; Thu, 17 Aug 2023 16:12:44 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:55539) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWjMF-0006C6-AX for 63829@debbugs.gnu.org; Thu, 17 Aug 2023 16:12:43 -0400 In-Reply-To: (Spencer Baugh's message of "Thu, 17 Aug 2023 15:41:47 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:267696 Archived-At: --=-=-= Content-Type: text/plain Spencer Baugh 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Use-current-file-name-for-more-other-project-future-.patch >From 48880a795f75d1126a0f235bf57f00f478ee90a0 Mon Sep 17 00:00:00 2001 From: Spencer Baugh 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 --=-=-=--