From: "Simen Heggestøyl" <simenheg@runbox.com>
To: 41741@debbugs.gnu.org
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
Dmitry Gutov <dgutov@yandex.ru>, Juri Linkov <juri@linkov.net>
Subject: bug#41741: [PATCH] Save project list as lisp data
Date: Sat, 06 Jun 2020 18:40:05 +0200 [thread overview]
Message-ID: <35622.6527875819$1591469962@news.gmane.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 329 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Save-project-list-as-lisp-data.patch --]
[-- Type: text/x-diff, Size: 3258 bytes --]
From 3084f651d6c0f5e6b4b3ac699b59742f98af2248 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@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
next reply other threads:[~2020-06-06 16:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 16:40 Simen Heggestøyl [this message]
[not found] <877dwkno62.fsf@simenheg@gmail.com>
2020-06-06 22:59 ` bug#41741: [PATCH] Save project list as lisp data Dmitry Gutov
2020-06-07 19:55 ` Simen Heggestøyl
[not found] ` <87wo4ips6d.fsf@simenheg@gmail.com>
2020-06-07 20:18 ` Dmitry Gutov
2020-06-08 19:00 ` Simen Heggestøyl
[not found] ` <873675jsbv.fsf@simenheg@gmail.com>
2020-06-08 20:32 ` Dmitry Gutov
2020-06-09 18:48 ` Simen Heggestøyl
2020-06-08 23:09 ` Juri Linkov
2020-06-08 23:39 ` Dmitry Gutov
2020-06-08 23:48 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='35622.6527875819$1591469962@news.gmane.org' \
--to=simenheg@runbox.com \
--cc=41741@debbugs.gnu.org \
--cc=contovob@tcd.ie \
--cc=dgutov@yandex.ru \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).