From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Newsgroups: gmane.emacs.bugs Subject: bug#41741: [PATCH] Save project list as lisp data Date: Mon, 08 Jun 2020 21:00:36 +0200 Message-ID: <36303.2496463106$1591642972@news.gmane.org> References: <877dwkno62.fsf@simenheg@gmail.com> <87wo4ips6d.fsf@simenheg@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="805"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.91 (gnu/linux) Cc: "Basil L. Contovounesios" , 41741@debbugs.gnu.org, Juri Linkov To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 08 21:02:51 2020 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 1jiN2p-00009W-4H for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Jun 2020 21:02:51 +0200 Original-Received: from localhost ([::1]:56354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiN2o-0008Pa-21 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Jun 2020 15:02:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiN14-0007bS-7t for bug-gnu-emacs@gnu.org; Mon, 08 Jun 2020 15:01:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46382) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jiN13-0005b4-Pu for bug-gnu-emacs@gnu.org; Mon, 08 Jun 2020 15:01:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jiN13-0002IM-OP for bug-gnu-emacs@gnu.org; Mon, 08 Jun 2020 15:01:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 08 Jun 2020 19:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41741 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41741-submit@debbugs.gnu.org id=B41741.15916428558801 (code B ref 41741); Mon, 08 Jun 2020 19:01:01 +0000 Original-Received: (at 41741) by debbugs.gnu.org; 8 Jun 2020 19:00:55 +0000 Original-Received: from localhost ([127.0.0.1]:57928 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jiN0w-0002Ht-KS for submit@debbugs.gnu.org; Mon, 08 Jun 2020 15:00:54 -0400 Original-Received: from aibo.runbox.com ([91.220.196.211]:41924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jiN0t-0002Hj-Qy for 41741@debbugs.gnu.org; Mon, 08 Jun 2020 15:00:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From; bh=HnVaVI3WDG1GzH33hDMUen5MymxqTcZ41+zIYUpm5LM=; b=cKDJ1OIDvdMq7g3Al7S/haBG9V YSPnMV31ZVnTv0gVPjsCFqd9/RSXQz3O+qRuydrk1o/ohta+Dd0wNZlAlPb93gsxN3PnWynthrsP6 3PxyzOlxVQsbnNLbMntwHbm//HManYXtG/ahbl/DE4oYq4dMbXb/SiX7pzdjfERL89Z5I/jJUH4oH au+qetx8MfV/QSeBMSGoe0sLICN0M2rujJqFgL46CNe8KIYTMCLI4oXtquVNX2Gy1bnFlNez94Fh/ fs/nhti/YN9p4V9pRvq+Qe0nE+2u4iFJX5045CHUGeSWFVU3VfzEVZMZBGxjkZdnxr7DPCDcxRtPE wZLgH8ww==; Original-Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1jiN0q-0002ic-JH; Mon, 08 Jun 2020 21:00:48 +0200 Original-Received: by submission01.runbox with esmtpsa [Authenticated alias (963757)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1jiN0e-0002XX-EA; Mon, 08 Jun 2020 21:00:36 +0200 In-Reply-To: (Dmitry Gutov's message of "Sun, 7 Jun 2020 23:18:26 +0300") 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" Xref: news.gmane.io gmane.emacs.bugs:181746 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dmitry Gutov writes: > On 07.06.2020 22:55, Simen Heggest=C3=B8yl wrote: > >> It is transient now, yes. > > And later, it won't be? Yes, later too (sorry, I think I misunderstood your original message). >> Just as an example I can imagine an optional feature in the future where >> you could name a project interactively the first time it's seen >> (i.e. when it's added to the project list for the first time). > > And then lose all these annotations when a project root directory is > moved/renamed/etc? > > But OK, maybe it won't happen too often to really worry about. Yes. I think it should only be used to store metadata that isn't a hassle to lose. Another example from the top of my head: recording project visit counts. That could be used for an option to show the most popular projects first in the completion list, for instance. >>> AKA: >>> >>> (goto-char (point-min)) >>> (read (current-buffer)) >>> >>> Though the practical difference will be tiny. >> I don't mind changing it, but could you explain the difference to >> me? My >> understanding isn't deep enough to see anything but one line versus >> two. :) > > Just an extra string allocation, I guess. Sure, I've changed it. Updated patch attached! -- Simen --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Save-project-list-as-lisp-data.patch >From 6a907d09b9a5b341f5c01f93fd031cb45229f320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Fri, 5 Jun 2020 19:32:30 +0200 Subject: [PATCH] Save project list as lisp data Save the project list file as lisp data instead of line separated strings to make it more extendable in the future. * lisp/progmodes/project.el (project--read-project-list) (project--write-project-list, project--add-to-project-list-front) (project--remove-from-project-list): Adjust to `project--list' now being an alist. --- lisp/progmodes/project.el | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 4d57fb25fd..0cca518d26 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -763,13 +763,8 @@ project--read-project-list (when (file-exists-p filename) (with-temp-buffer (insert-file-contents filename) - (let ((dirs (split-string (buffer-string) "\n" t)) - (project-list '())) - (dolist (dir dirs) - (cl-pushnew (file-name-as-directory dir) - project-list - :test #'equal)) - (reverse project-list))))))) + (goto-char (point-min)) + (read (current-buffer))))))) (defun project--ensure-read-project-list () "Initialize `project--list' if it hasn't already been." @@ -780,7 +775,8 @@ project--write-project-list "Persist `project--list' to the project list file." (let ((filename project-list-file)) (with-temp-buffer - (insert (string-join project--list "\n")) + (insert ";;; -*- lisp-data -*-\n") + (pp project--list (current-buffer)) (write-region nil nil filename nil 'silent)))) (defun project--add-to-project-list-front (pr) @@ -788,9 +784,9 @@ project--add-to-project-list-front Save the result to disk if the project list was changed." (project--ensure-read-project-list) (let ((dir (project-root pr))) - (unless (equal (car project--list) dir) - (setq project--list (delete dir project--list)) - (push dir project--list) + (unless (equal (caar project--list) dir) + (setq project--list (assoc-delete-all dir project--list)) + (push (list dir) project--list) (project--write-project-list)))) (defun project--remove-from-project-list (pr-dir) @@ -798,8 +794,8 @@ project--remove-from-project-list If the directory was in the list before the removal, save the result to disk." (project--ensure-read-project-list) - (when (member pr-dir project--list) - (setq project--list (delete pr-dir project--list)) + (when (assoc pr-dir project--list) + (setq project--list (assoc-delete-all pr-dir project--list)) (message "Project `%s' not found; removed from list" pr-dir) (project--write-project-list))) -- 2.26.2 --=-=-=--