From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#66260: 29.0.92; project.el should support copying a file path relative to the project root Date: Sat, 21 Oct 2023 13:13:34 +0000 (UTC) Message-ID: <87jzrgt8xu.fsf@catern.com> References: <875y3t2827.fsf@catern.com> <15010505-0b2f-5dc3-e16a-228183779d43@gutov.dev> 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="27024"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66260@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 21 15:14:51 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 1quBoX-0006nn-9v for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Oct 2023 15:14:50 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quBoJ-0002SN-Vm; Sat, 21 Oct 2023 09:14:36 -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 1quBoI-0002Nm-Rg for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2023 09:14:34 -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 1quBoI-0007Y6-H0 for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2023 09:14:34 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1quBok-0008HO-7y for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2023 09:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Oct 2023 13:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66260 X-GNU-PR-Package: emacs Original-Received: via spool by 66260-submit@debbugs.gnu.org id=B66260.169789405131743 (code B ref 66260); Sat, 21 Oct 2023 13:15:02 +0000 Original-Received: (at 66260) by debbugs.gnu.org; 21 Oct 2023 13:14:11 +0000 Original-Received: from localhost ([127.0.0.1]:42549 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quBnv-0008Fu-3M for submit@debbugs.gnu.org; Sat, 21 Oct 2023 09:14:11 -0400 Original-Received: from s.wfbtzhsv.outbound-mail.sendgrid.net ([159.183.224.104]:9002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quBns-0008Fc-G5 for 66260@debbugs.gnu.org; Sat, 21 Oct 2023 09:14:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: cc:content-type:from:subject:to; s=s1; bh=IwZ3Uv8253ab+6tur8LUIA6GPQ1t8cRUB1/C/Z8nxe8=; b=OvmFsYVJ3qjTfetb7vjxedPSbnTdUXw/4Z6M78In7Pteb0gTlRV9XpNM18RqQLZKT3MU KoMeDESweZ8FmnyGfM4VXm7Xx7SLaFzuUd/vNC8lhhhyPTtvp6zC++2fP1B0iMA+HVx+rW DqH08whzaLEy16NpcKve0UnB+czXxRVwTAr4e8INQD4zF1PK/YiPsYjNUDOGzXkBjbfXNS BpUNXCCZFeOmnKqNqfAy+RCvUcDuOKyHuurhzzbwuKG/M8X1RYT6l41bxV8aCmTKN4Y4kY W/yMroZFlpmLP7Lq1EcKg0bRugrqOQo3zpZGIsR2kqOYI9Qj2FB61VteKJJbIzNg== Original-Received: by filterdrecv-6b68c9f446-8bxlf with SMTP id filterdrecv-6b68c9f446-8bxlf-1-6533CE7D-29 2023-10-21 13:13:33.974753895 +0000 UTC m=+325962.811723049 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-0 (SG) with ESMTP id dfMti6vFQW2fBZCSBV83_Q Sat, 21 Oct 2023 13:13:33.886 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=gutov.dev Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id 626EE601BB; Sat, 21 Oct 2023 09:13:33 -0400 (EDT) In-Reply-To: <15010505-0b2f-5dc3-e16a-228183779d43@gutov.dev> (Dmitry Gutov's message of "Mon, 2 Oct 2023 01:44:38 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbJEH/P2L4/q99KQJRVSKiN47/wAAS3UQvWN+RhbX9ceUgoL6cTvB1rrHba0M1tiscDyD0kHBuz3GXbWLRmeyce66VxC6eSllm3loOLnHIOXIcXRhYJ+VmDJWQUuAkIcjWt6We9Pg30/YdKBER5f5jF77OYZepl1g36/VP8BYTss/w== X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== 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:272894 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Dmitry Gutov writes: > On 29/09/2023 02:26, sbaugh@catern.com wrote: >> When communicating with others, it is often useful to copy a file path >> to the current file which is relative to the project root. For example >> I'd rather send someone the path lisp/progmodes/project.el than >> ~/src/emacs/trunk/lisp/progmodes/project.el. >> project.el should have a way to copy this file path. >> Almost good enough is: >> C-x p f ;; project-find-file >> M-n ;; next-history-element >> C-k ;; kill-line >> but with project--read-file-cpd-relative, if all the files in >> project-files start with a common-parent-directory which is a >> subdirectory of project-root, the resulting file path will not be >> relative to the project-root but to the subdirectory. > > A problem with modifying the above function's behavior like that is > that sometimes it is passed a wider range of file names, where not all > of them are inside the project root (M-x > project-or-external-find-file). Oh, what if we just *check* if the common-parent-directory is below the project root, and in that case use the project root instead? That elegantly resolves this without breaking that. Like this: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Use-project-root-in-project-find-file-if-all-files-a.patch >From c5b2e49cc8117e063d9e16a9072eb07ddff8aaa5 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 21 Oct 2023 09:11:52 -0400 Subject: [PATCH] Use project-root in project-find-file if all files are below it project-files can return a list of files all of whom are in a subdirectory of project-root. We should still use project-root in project--read-file-cpd-relative in that case, for several reasons: - Now M-n will always bring up the full path of the current file for copying - Now if the user wants to manually type in a path starting at the root, they can. * lisp/progmodes/project.el (project--read-file-cpd-relative): Always use project-root if all files are below that. (bug#66260) --- lisp/progmodes/project.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 0d6539113cc..dcd1cab4f96 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1117,9 +1117,16 @@ project--read-file-cpd-relative MB-DEFAULT is used as part of \"future history\", to be inserted by the user at will." (let* ((common-parent-directory - (let ((common-prefix (try-completion "" all-files))) - (if (> (length common-prefix) 0) - (file-name-directory common-prefix)))) + (let* ((common-prefix (try-completion "" all-files)) + (root (project-root (project-current))) + (expand-root (expand-file-name root)) + (abbrev-root (abbreviate-file-name root))) + (cond + ;; We try use the project-root even if all the files have + ;; a c-p-d below the project-root. + ((string-prefix-p expand-root common-prefix) expand-root) + ((string-prefix-p abbrev-root common-prefix) abbrev-root) + ((> (length common-prefix) 0) (file-name-directory common-prefix))))) (cpd-length (length common-parent-directory)) (prompt (if (zerop cpd-length) prompt -- 2.41.0 --=-=-=--