Do some cleanup in db-projects

This commit is contained in:
Daniel - 2020-09-20 16:20:23 +02:00
parent 9822736d8e
commit 7a0fbff4c5
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
1 changed files with 18 additions and 17 deletions

View File

@ -80,8 +80,7 @@ with some standard information like title and creation date."
(if-let ((git-executable (executable-find "git"))) (if-let ((git-executable (executable-find "git")))
(call-process git-executable nil nil nil "init") (call-process git-executable nil nil nil "init")
(write-region "" nil (expand-file-name ".projectile"))) (write-region "" nil (expand-file-name ".projectile")))
(when (require 'projectile nil 'no-error) (projectile-add-known-project project-directory)))
(projectile-add-known-project project-directory))))
(defun projects--find-bookmarks-for-path (path) (defun projects--find-bookmarks-for-path (path)
"Find all bookmark names that point into PATH." "Find all bookmark names that point into PATH."
@ -106,24 +105,26 @@ project, and updating projectile's cache."
(unless (projects-project-exists-p short-name) (unless (projects-project-exists-p short-name)
(user-error "Project %s does not exist, exiting" short-name)) (user-error "Project %s does not exist, exiting" short-name))
;; Remove bookmarks first (let ((project-path (expand-file-name short-name projects-main-project-directory))
(mapc #'bookmark-delete (projects--find-bookmarks-for-path (archive-path (expand-file-name short-name projects-archive-directory)))
(expand-file-name short-name projects-main-project-directory)))
;; Move project directory into archive (when (file-exists-p archive-path)
(unless (file-exists-p projects-archive-directory) (user-error "Archived project named %s already exists, aborting" short-name))
(make-directory projects-archive-directory))
(rename-file (expand-file-name short-name projects-main-project-directory)
(expand-file-name short-name projects-archive-directory)
nil)
;; Update projectiles cache ;; Remove bookmarks first
(projectile-remove-known-project (mapc #'bookmark-delete (projects--find-bookmarks-for-path project-path))
(expand-file-name short-name
projects-main-project-directory))) ;; Move project directory into archive
(unless (file-exists-p projects-archive-directory)
(make-directory projects-archive-directory))
(rename-file project-path archive-path nil)
;; Update projectiles cache
(projectile-cleanup-known-projects)))
(defun projects--org-files () (defun projects--org-files ()
"Return all Org Mode files in all known projects, recursively." "Return all Org Mode files in all known projects, recursively.
Paths returned are absolute, but may not be canonical."
(mapcan #'(lambda (dir) (mapcan #'(lambda (dir)
(directory-files-recursively (expand-file-name dir projects-main-project-directory) (directory-files-recursively (expand-file-name dir projects-main-project-directory)
".*\\.org" nil)) ".*\\.org" nil))
@ -159,7 +160,7 @@ not have a corresponding bookmark."
"projekttagebuch.org") "projekttagebuch.org")
projects-main-project-directory))) projects-main-project-directory)))
(when (file-exists-p project-diary-path) (when (file-exists-p project-diary-path)
(puthash project-diary-path project projects)))) (puthash (file-truename project-diary-path) project projects))))
;; Delete all those diary links that have a bookmark ;; Delete all those diary links that have a bookmark
(dolist (bmkn (bookmark-all-names)) (dolist (bmkn (bookmark-all-names))