[Projects] Add simple project management library

This commit is contained in:
Daniel - 2018-08-05 16:19:52 +02:00
parent b4185de60f
commit 6da48163df
Signed by: dbo
GPG Key ID: 4F63DB96D45AA9C6
2 changed files with 73 additions and 0 deletions

View File

@ -1261,6 +1261,9 @@ are assumed to be of the form *.crt."
crux-cleanup-buffer-or-region
crux-delete-buffer-and-file))
(use-package db-projects
:commands (projects-add-project projects-archive-project))
(use-package define-word
:commands (define-word-at-point define-word))

70
site-lisp/db-projects.el Normal file
View File

@ -0,0 +1,70 @@
;;; db-projects.el -- Simple Directory-Based Project Management -*- lexical-binding: t -*-
;;; Commentary:
;; XXX: add projectile integration
;;; Code:
(defgroup projects nil
"Simple directory-based project management"
:tag "Project Management"
:group 'projects)
(defcustom projects-main-project-directory "~/Documents/projects/"
"Main directory to host projects."
:group 'projects)
(defcustom projects-archive-directory "~/Documents/projects/.archive"
"Directory to archive projects into"
:group 'projects)
(defun projects-project-exists-p (short-name)
"Check whether a project named SHORT-NAME already exists"
(file-exists-p (expand-file-name ".projectile"
(expand-file-name short-name
projects-main-project-directory))))
(defun projects-existing-projects ()
"Return list of all short-names of existing projects"
(cl-remove-if-not (lambda (name)
(file-exists-p (expand-file-name ".projectile"
(expand-file-name name projects-main-project-directory))))
(directory-files projects-main-project-directory)))
(defun projects-add-project (short-name long-name)
"Add new project."
(interactive "sShort Name: \nsLong Name: ")
(when (projects-project-exists-p short-name)
(user-error "Project %s already exists, existing" short-name))
(let ((project-directory (expand-file-name short-name
projects-main-project-directory)))
(make-directory project-directory)
(make-directory (expand-file-name "scripts" project-directory))
(make-directory (expand-file-name "data" project-directory))
(with-temp-buffer
(insert (format "#+title: %s\n" long-name))
(insert (format "#+created: %s\n\n"
(format-time-string "[%Y-%m-%d %a %H:%M]" (current-time))))
(write-file (expand-file-name "projekttagebuch.org" project-directory))
(bookmark-set (format "Projekttagebuch %s" short-name)))
(with-temp-buffer
(insert (format "%s" long-name))
(write-file (expand-file-name ".projectile" project-directory)))))
(defun projects-archive-project (short-name)
"Archive existing project."
(interactive (list
(completing-read "Short Name: " (projects-existing-projects) nil t)))
(unless (projects/project-exists-p short-name)
(user-error "Project %s does not exist, exiting" short-name))
(unless (file-exists-p projects-archive-directory)
(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)
(bookmark-delete (format "Projekttagebuch %s" short-name)))
(provide 'db-projects)
;;; db-projects.el ends here