From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov 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 05:14:03 +0300 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: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33703"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: Spencer Baugh , Juri Linkov , 63829@debbugs.gnu.org To: sbaugh@catern.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 17 04:15:22 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 1qWSXh-0008VO-1K for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Aug 2023 04:15:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWSXV-0004jc-Mp; Wed, 16 Aug 2023 22:15:09 -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 1qWSXS-0004ix-MO for bug-gnu-emacs@gnu.org; Wed, 16 Aug 2023 22:15:06 -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 1qWSXO-0003CB-7h for bug-gnu-emacs@gnu.org; Wed, 16 Aug 2023 22:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qWSXO-0002Ou-2s for bug-gnu-emacs@gnu.org; Wed, 16 Aug 2023 22:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 17 Aug 2023 02:15:02 +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.16922384569140 (code B ref 63829); Thu, 17 Aug 2023 02:15:02 +0000 Original-Received: (at 63829) by debbugs.gnu.org; 17 Aug 2023 02:14:16 +0000 Original-Received: from localhost ([127.0.0.1]:42401 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWSWd-0002NL-EV for submit@debbugs.gnu.org; Wed, 16 Aug 2023 22:14:15 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:52365) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWSWb-0002N4-0V for 63829@debbugs.gnu.org; Wed, 16 Aug 2023 22:14:14 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id AB5395C00BA; Wed, 16 Aug 2023 22:14:07 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 16 Aug 2023 22:14:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1692238447; x=1692324847; bh=EnMBQH6omlO9XT7McfPgrqBaUygSM2GlmEN fpCTV0KA=; b=Ew4uvdKIFTeaWjrsjln5c0mGxXTJ6Btrg5f54GG15MvyUCYU2eU YLlWX4kc8Ve0eTI93x6EZhnj1KiTUDFcdQvwpdERa5OR0fz1Wam2OEuwvmWZ+PoX 5RlPl/eKVvFihEbgzZCBWu6jUSIJyq3CtbQTQF13rCOHuu/oqsTIlSlyNPgHTARR iqq2DGm6CB5eVOZUCFoJiAdYUQct9lYBfUsbizwY/TpcUsQ5S8Y284OzNiLybwTx Iw2kgqDYRv9cxs+EKSrjbttF6zM5rCi9LCv/te6ovH0A3h2phnDJe/P9Mhx2OwUk IF9lXhWrTUojRB63IoOj973zGMKiYzVH3QQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1692238447; x=1692324847; bh=EnMBQH6omlO9XT7McfPgrqBaUygSM2GlmEN fpCTV0KA=; b=X5B1Xr0zAXmlDBHWay94uxc8xrn2mR7UdT1x7Ph34a0PnYGaB1K LGTDty9AGowPQxJr/4FdwrQrSsdWCFnbBrNGeikplvfNscSBJnQMBVIJGCy3doTM pc9HbsjFiPtguux3U2AmSOPxhiATnjpCbDgDiPRqsAx/nRsFn7HGbdokjMQEJ168 og0dmSi/we0MpxuTmb4ZRmD+h6NzaU74/MZW69KcFQXbHps5vTLBIHZ3UWXHJn/p di6zKRwmpkto8rGDZ22c8aLYZu7lABdf5OdtnCXmVtNB0ja5lDQYZq1OAGO5eLZI ipnCpWdJsvpM8ZJWqRfvhuq8gyVdY9vpq7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddutddgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepiefgteevheevveffheeltdeukeeiieekueefgedugfefgefhudelgfefveel vdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 16 Aug 2023 22:14:06 -0400 (EDT) Content-Language: en-US In-Reply-To: <875y5fitiq.fsf@catern.com> 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:267623 Archived-At: On 16/08/2023 05:57, sbaugh@catern.com wrote: >> Now that you can have this additional capability as an option, do you >> think you will be using it as well? > > Yes, probably I will enable this shared project history mode for my > users. Nice. >> Before we do that, small (or not so small) question: do you think we >> should test that the current buffer exists in the other project too? >> We could do that with file-exists-p (but that's an extra round-trip >> over Tramp), or by checking against the full list like in below. > > No, I don't think that's necessary. It produces more consistent > behavior to not check whether the file exists. And anyway, it could > maybe be helpful to be able to create the same file in another project. Fair point. Creating new files it is, then. >> Relatedly, with the cross-project history, we should ask the same >> question: will we check that the "transplanted" history entries >> correspond to existing files in the other project (and filter out >> those that don't). > > Likewise I don't think that's necessary. > > Although it might be nice to support a user-supplied predicate which, > given the current project and a path in the history (which contains as a > property the originating project), determines whether to show that path. > Then the user could filter the history to only paths in "sibling > projects" with similar content. Not required though. OK, we can easily add such a predicate later, if somebody asks. I'm pushed the first of your patches, but the second needed some adjustments. Chiefly because we need to make sure it works with any value of project-read-file-name-function, so the impl can't be concentrated in just one of them. Check out the amended patch below. Any suggestions on how to do it more elegantly (without duplicating the add-to-history call) are welcome too. diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index e1d14474323..d810d8d9605 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1046,6 +1046,13 @@ project-read-file-name-function :group 'project :version "27.1") +(defun project--expand-file-name (filename project) + (when-let ((old-root (get-text-property 0 'project filename))) + (abbreviate-file-name + (expand-file-name + (file-relative-name filename old-root) + (project-root project))))) + (defun project--read-file-cpd-relative (prompt all-files &optional predicate hist mb-default) @@ -1124,9 +1131,18 @@ project-find-file-in dirs) (project-files project dirs))) (completion-ignore-case read-file-name-completion-ignore-case) - (file (funcall project-read-file-name-function - "Find file" all-files nil 'file-name-history - suggested-filename))) + (file + (let ((file-name-history (mapcar + (lambda (f) + (or (project--expand-file-name f project) f)) + file-name-history))) + (funcall project-read-file-name-function + "Find file" all-files nil 'file-name-history + suggested-filename)))) + (when history-add-new-input + ;; Have to re-add it here because of the let-binding above. + (add-to-history 'file-name-history + (propertize file 'project (project-root project)))) (if (string= file "") (user-error "You didn't specify the file") (find-file file))))