GNU bug report logs - #41741
[PATCH] Save project list as lisp data

Previous Next

Package: emacs;

Reported by: Simen Heggestøyl <simenheg <at> runbox.com>

Date: Sat, 6 Jun 2020 18:58:02 UTC

Severity: normal

Tags: patch

Done: Simen Heggestøyl <simenheg <at> runbox.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Simen Heggestøyl <simenheg <at> runbox.com>
Subject: bug#41741: closed (Re: bug#41741: [PATCH] Save project list as
 lisp data)
Date: Tue, 09 Jun 2020 18:49:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#41741: [PATCH] Save project list as lisp data

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 41741 <at> debbugs.gnu.org.

-- 
41741: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=41741
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Simen Heggestøyl <simenheg <at> runbox.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>, 41741-done <at> debbugs.gnu.org,
 Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#41741: [PATCH] Save project list as lisp data
Date: Tue, 09 Jun 2020 20:48:04 +0200
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> On 08.06.2020 22:00, Simen Heggestøyl wrote:
>
>> Updated patch attached!
>
> All good!

Installed! Thanks for reviewing.

-- Simen

[Message part 3 (message/rfc822, inline)]
From: Simen Heggestøyl <simenheg <at> runbox.com>
To: bug-gnu-emacs <at> gnu.org
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>, Juri Linkov <juri <at> linkov.net>,
 Dmitry Gutov <dgutov <at> yandex.ru>
Subject: [PATCH] Save project list as lisp data
Date: Sat, 06 Jun 2020 18:40:05 +0200
[Message part 4 (text/plain, inline)]
Hi.

I'm attaching a suggested patch for changing project.el's project list
format from a line based one to proper Lisp data as discussed in the
"New feature in project.el: Remembering the previously used projects"
thread on emacs-devel.

No metadata is added at this point, but it makes it extensible for the
future.

-- Simen

[0001-Save-project-list-as-lisp-data.patch (text/x-diff, inline)]
From 3084f651d6c0f5e6b4b3ac699b59742f98af2248 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg <at> gmail.com>
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 | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 4d57fb25fd..3b007bc8dc 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -757,19 +757,13 @@ project--list
   "List of known project directories.")
 
 (defun project--read-project-list ()
-  "Initialize `project--list' from the project list file."
+  "Initialize `project--list' from the file `project-list-file'."
   (let ((filename project-list-file))
     (setq project--list
-          (when (file-exists-p filename)
+          (when (file-readable-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)))))))
+              (car (read-from-string (buffer-string))))))))
 
 (defun project--ensure-read-project-list ()
   "Initialize `project--list' if it hasn't already been."
@@ -780,7 +774,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 +783,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 +793,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


This bug report was last modified 4 years and 346 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.