GNU bug report logs -
#41741
[PATCH] Save project list as lisp data
Previous Next
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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41741 in the body.
You can then email your comments to 41741 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Sat, 06 Jun 2020 18:58:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Simen Heggestøyl <simenheg <at> runbox.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 06 Jun 2020 18:58:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Sat, 06 Jun 2020 23:00:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 41741 <at> debbugs.gnu.org (full text, mbox):
Hi Simen,
On 06.06.2020 19:40, Simen Heggestøyl wrote:
> 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.
Some comments below.
> No metadata is added at this point, but it makes it extensible for the
> future.
I'm not sure we'd really be able to store metadata in it. The list is
more or less transient: the entries are added automatically, and removed
automatically as well. If someone needs to know something about a
project, it's better to leave that to an overridable method, and maybe
add a project-vc- variable (if that value needs to be user-customizable).
For that reason, we should probably opt for storing directories only.
> - "Initialize `project--list' from the project list file."
> + "Initialize `project--list' from the file `project-list-file'."
I think the previous string was okay.
> - (when (file-exists-p filename)
> + (when (file-readable-p filename)
What's the difference? File exists, but belongs to another account? I'm
not sure we'd want to silently fail in that case (kinda puzzling
behavior), and writing to the file is likely to fail later too.
> + (car (read-from-string (buffer-string))))))))
AKA:
(goto-char (point-min))
(read (current-buffer))
Though the practical difference will be tiny.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Sun, 07 Jun 2020 19:56:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 41741 <at> debbugs.gnu.org (full text, mbox):
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 06.06.2020 19:40, Simen Heggestøyl wrote:
>
>> No metadata is added at this point, but it makes it extensible for the
>> future.
>
> I'm not sure we'd really be able to store metadata in it. The list is
> more or less transient: the entries are added automatically, and
> removed automatically as well. If someone needs to know something
> about a project, it's better to leave that to an overridable method,
> and maybe add a project-vc- variable (if that value needs to be
> user-customizable).
>
> For that reason, we should probably opt for storing directories only.
It is transient now, yes. But the biggest gain from going from the
one-directory-per-line format to the proposed alist format is (in my
view) having the possibility to extend its uses in the future without
breaking backward compatibility with existing project list files.
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). I
wouldn't like to maintain that in my config file; having the name live
in the project list only would be fine with me. That would require
extending project.el to keep project metadata when rearranging them.
>> - "Initialize `project--list' from the project list file."
>> + "Initialize `project--list' from the file `project-list-file'."
>
> I think the previous string was okay.
Alright, reverted.
>> - (when (file-exists-p filename)
>> + (when (file-readable-p filename)
>
> What's the difference? File exists, but belongs to another account?
> I'm not sure we'd want to silently fail in that case (kinda puzzling
> behavior), and writing to the file is likely to fail later too.
Hm, yes. I snatched that part from saveplace.el, but after you pointed
it out I now also think it's better to get an error in that
case. Reverted.
>> + (car (read-from-string (buffer-string))))))))
>
> 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. :)
-- Simen
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Sun, 07 Jun 2020 20:19:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 41741 <at> debbugs.gnu.org (full text, mbox):
On 07.06.2020 22:55, Simen Heggestøyl wrote:
> It is transient now, yes.
And later, it won't be?
> 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.
>>> - (when (file-exists-p filename)
>>> + (when (file-readable-p filename)
>>
>> What's the difference? File exists, but belongs to another account?
>> I'm not sure we'd want to silently fail in that case (kinda puzzling
>> behavior), and writing to the file is likely to fail later too.
>
> Hm, yes. I snatched that part from saveplace.el, but after you pointed
> it out I now also think it's better to get an error in that
> case. Reverted.
Perhaps we should change saveplace as well. :-)
>>> + (car (read-from-string (buffer-string))))))))
>>
>> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Mon, 08 Jun 2020 19:01:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 41741 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 07.06.2020 22:55, Simen Heggestøyl 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
[0001-Save-project-list-as-lisp-data.patch (text/x-diff, inline)]
From 6a907d09b9a5b341f5c01f93fd031cb45229f320 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 | 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Mon, 08 Jun 2020 20:33:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 41741 <at> debbugs.gnu.org (full text, mbox):
On 08.06.2020 22:00, Simen Heggestøyl wrote:
> 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.
OK then.
> Updated patch attached!
All good!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Mon, 08 Jun 2020 23:39:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 41741 <at> debbugs.gnu.org (full text, mbox):
> 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.
Or record project visit time, and then sort by time,
so that the most recently used projects are first.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Mon, 08 Jun 2020 23:40:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 41741 <at> debbugs.gnu.org (full text, mbox):
On 09.06.2020 02:09, Juri Linkov wrote:
> Or record project visit time, and then sort by time,
> so that the most recently used projects are first.
We currently do that by changing the order of the entries.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41741
; Package
emacs
.
(Mon, 08 Jun 2020 23:49:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 41741 <at> debbugs.gnu.org (full text, mbox):
> > 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.
>
> Or record project visit time, and then sort by time,
> so that the most recently used projects are first.
Haven't been following this thread; sorry.
But this is one of the things bookmarks are great for.
Whatever it is, bookmark it, and use the bookmark to
access it. Each time you do, the bookmark updates
the date+time visited and the number of visits.
Nothing else is needed, just the ability to bookmark
something. And you can do that for pretty much
anything you can visit. If no existing bookmark type
is relevant you can easily define a new bookmark type.
Reply sent
to
Simen Heggestøyl <simenheg <at> runbox.com>
:
You have taken responsibility.
(Tue, 09 Jun 2020 18:49:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Simen Heggestøyl <simenheg <at> runbox.com>
:
bug acknowledged by developer.
(Tue, 09 Jun 2020 18:49:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 41741-done <at> debbugs.gnu.org (full text, mbox):
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
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 08 Jul 2020 11:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 345 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.