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#64088: [PATCH] Make project-root for vc projects return an absolute path Date: Sat, 19 Aug 2023 12:57:19 +0000 (UTC) Message-ID: <87lee7gpg1.fsf@catern.com> References: <3c6078aa-4089-46fd-18bb-d92be101ca4f@gutov.dev> <2690528f-bfc8-d164-c522-cd2fcf2ba1ba@gutov.dev> <16c053e0-cd4b-295d-2dae-e97bcf25f3b3@gutov.dev> <87ttsvgqnt.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="40324"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Spencer Baugh , 64088@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 19 14:58:13 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 1qXLWt-000AE3-1O for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Aug 2023 14:58:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXLWk-0007dg-Jx; Sat, 19 Aug 2023 08:58:02 -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 1qXLWj-0007dU-8C for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 08:58:01 -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 1qXLWi-0000KZ-Vi for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 08:58:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qXLWj-0006IG-UJ for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 08:58:01 -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, 19 Aug 2023 12:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64088 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64088-submit@debbugs.gnu.org id=B64088.169244985424156 (code B ref 64088); Sat, 19 Aug 2023 12:58:01 +0000 Original-Received: (at 64088) by debbugs.gnu.org; 19 Aug 2023 12:57:34 +0000 Original-Received: from localhost ([127.0.0.1]:49686 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXLWH-0006HY-MH for submit@debbugs.gnu.org; Sat, 19 Aug 2023 08:57:34 -0400 Original-Received: from s.wrqvwxzv.outbound-mail.sendgrid.net ([149.72.154.232]:2656) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXLWA-0006HC-Mp for 64088@debbugs.gnu.org; Sat, 19 Aug 2023 08:57:32 -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=xqkjo/qb2GECda5DxVnG0vnQH4VjPI1GEGbmakv2Qz4=; b=d1tRK87h1iztF8mqx0GEg1axcHyQf61DvvfFEyrpqtZKLH4Wgz7NYGjAAOejtU75qGmV mP3u4BQ0elMq6sgZWXdj7UPVaPIMwyQUDqb5Zbt0jrron05lZZDc6+KG2cyMh8xOjGc1hd FEZjy1CmSwKwJeqfKZJmvvN1lMbx5hRNlrZyxDfzeQdCzVV8StQlx6IX7ALbqL+REsC5VV EBlDKJnWpzrWyl8+cqthLIdDLxqkl3s2EsDdeV+y0Dh8I6lpnBoDmwQPrT6eW1n6F6hIsG 78bOjj6TdDYeUnK2GuCe7Z5oQ4GrPpFVuHEKJri4/EiGwOsE6V3mKgyvGDWrHgjw== Original-Received: by filterdrecv-8684c58db7-zm958 with SMTP id filterdrecv-8684c58db7-zm958-1-64E0BC2E-1C 2023-08-19 12:57:18.950200136 +0000 UTC m=+8687913.317366625 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-10 (SG) with ESMTP id bnJQXv3vTDCfpspgR34HWQ Sat, 19 Aug 2023 12:57:18.693 +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 35A496001E; Sat, 19 Aug 2023 08:57:18 -0400 (EDT) In-Reply-To: <87ttsvgqnt.fsf@catern.com> (sbaugh@catern.com's message of "Sat, 19 Aug 2023 12:31:03 +0000 (UTC)") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbIC9Pqd89V61obby29CniUrpxaUmZbv4JaWPOxTIIkcIC8jCGM9X5bpEUOgxceVzpktxVoD4lgtpie+rnF23khReJyfVXaAd8Tiruj2BCpJjQNnXgDTwfU9wriCt/bVPjnZvVcrqzZ+P6HZ86jqnWGTuPF6aXU1urynbxJyIl9fYg== 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:267865 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit sbaugh@catern.com writes: > Dmitry Gutov writes: >> On 11/07/2023 02:45, Spencer Baugh wrote: >>> Dmitry Gutov writes: >>>> On 27/06/2023 23:01, Spencer Baugh wrote: >>>>> OK, how about this? >>>> >>>> Maybe we should go in the other direction? And call >>>> abbreviate-file-name on them? >>>> >>>> Because otherwise in project-prompt-project-dir we'll always show the >>>> expanded directory names, taking up extra space and usually repeating >>>> the full name of the user's home directory for no good reason. >>> That seems reasonable if we let-bind directory-abbrev-alist to nil >>> around it; otherwise we'll be dependent on the user's configuration and >>> we might add a directory in one way, and then they add a new value to >>> directory-abbrev-alist and we add it again a second way. >> >> That's also fair. >> >>> Although maybe that's fine? And probably users of >>> directory-abbrev-alist would like to have those abbreviations show up in >>> project-prompt-project-dir. >> >> They probably would. But indeed if the list was saved with one >> configuration, and read with another, it could lead to a mistake. >> >>> Also we could always call abbreviate-file-name at >>> project-prompt-project-dir time. >> >> Meaning it will be called N times (for the number of projects) every >> time the list is displayed, instead of just once, when the project is >> saved/visited. But maybe it's fine too? How slow could that be? > > I was sad about this but I think I've got the solution now: We just > maintain project--list in abbreviated form and project-list-file in > expanded form. > > I think that solves all the problems: the persistent file is independent > of user configuration, so if the user changes their abbreviations > they'll get new ones the next time the file is read (presumably the next > time they run Emacs). But project--list is abbreviated, so > project-prompt-project-dir gets abbreviated dirs. > > It does mean that if they change their directory-abbrev-alist while > Emacs is running they could get duplicate entries, but that already > could happen before this patch, and it's not a big problem IMO. > > See patch below. Oops, this patch needed a few tweaks. Especially, skipping the expansion and abbreviation for remote files, to avoid making unnecesary remote connections. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Expand-project-file-names-before-storing-them.patch >From 9523b4dea1234083e65b141a281c1108f52b046b Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 19 Aug 2023 08:24:45 -0400 Subject: [PATCH] Expand project file names before storing them Before, whatever project-root returned, we stored as the root directory of the project in project-list and project-list-file. This could lead to duplicate entries or bad behavior if projects were accessed by different file names, e.g. both /home/user/src/emacs and ~/src/emacs. Now project-list-file contains only expanded paths and project--list contains only abbreviated paths. We abbreviate filenames before setting project--list, and expand filenames before writing to project-list-file. We only do this for local files, though, to avoid making remote connections; the situation will still be bad for remote projects, but at least this is an improvement. * lisp/progmodes/project.el (project--write-project-list): Call expand-file-name. (project--read-project-list, project-remember-project) (project--remove-from-project-list): Call abbreviate-file-name. --- lisp/progmodes/project.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 11fa93fb70d..21d5df8f0cc 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1586,7 +1586,12 @@ project--read-project-list (when (file-exists-p filename) (with-temp-buffer (insert-file-contents filename) - (read (current-buffer))))) + (mapcar + (lambda (elem) + (let ((name (car elem))) + (list (if (file-remote-p name) name + (abbreviate-file-name name))))) + (read (current-buffer)))))) (unless (seq-every-p (lambda (elt) (stringp (car-safe elt))) project--list) @@ -1606,7 +1611,12 @@ project--write-project-list (insert ";;; -*- lisp-data -*-\n") (let ((print-length nil) (print-level nil)) - (pp project--list (current-buffer))) + (pp (mapcar (lambda (elem) + (let ((name (car elem))) + (list (if (file-remote-p name) name + (expand-file-name name))))) + project--list) + (current-buffer))) (write-region nil nil filename nil 'silent)))) ;;;###autoload @@ -1615,7 +1625,7 @@ project-remember-project Save the result in `project-list-file' if the list of projects has changed, and NO-WRITE is nil." (project--ensure-read-project-list) - (let ((dir (project-root pr))) + (let ((dir (abbreviate-file-name (project-root pr)))) (unless (equal (caar project--list) dir) (dolist (ent project--list) (when (equal dir (car ent)) @@ -1631,7 +1641,7 @@ project--remove-from-project-list from the list using REPORT-MESSAGE, which is a format string passed to `message' as its first argument." (project--ensure-read-project-list) - (when-let ((ent (assoc project-root project--list))) + (when-let ((ent (assoc (abbreviate-file-name project-root) project--list))) (setq project--list (delq ent project--list)) (message report-message project-root) (project--write-project-list))) -- 2.41.0 --=-=-=--