-
Notifications
You must be signed in to change notification settings - Fork 1
/
metal-archives-org.el
80 lines (57 loc) · 2.77 KB
/
metal-archives-org.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;;; metal-archives-org.el --- Org-mode export of the metal archive database -*- lexical-binding: t; coding: utf-8 -*-
;; Copyright (C) 10 June 2020
;;
;; Author: Sébastien Le Maguer <[email protected]>
;; Package-Requires: ((emacs "26.3"))
;; Keywords: org, calendar
;; Version: 0.1
;; Homepage: https://github.com/seblemaguer/metal-archives.el
;; metal-archives-org is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; metal-archives-org is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
;; License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with metal-archives-org. If not, see http://www.gnu.org/licenses.
;;; Commentary:
;; This package provides an helper, metal-archives-org-generate-org-from-db, to dump the metal
;; archives database to an org-mode file
;;; Code:
(require 'metal-archives)
(defcustom metal-archives-org-template "* %s - %s :%s:\nSCHEDULED: <%s>\n:PROPERTIES:\n:GENRE: %s\n:CATEGORY: Release\n:END:\n"
"Org entry template. The formatting assume the quadriplet ARTIST, ALBUM, TYPE, DATE and GENRE."
:type 'string
:group 'metal-archives)
(defcustom metal-archives-org-target-file (format "%s/ma-archive.org" user-emacs-directory)
"The release org formatted file."
:type 'file
:group 'metal-archives)
(defun metal-archives-org~format-entry (entry)
"Format an ENTRY in org format to be added to the org agenda file."
(let* ((org-entry (format metal-archives-org-template
(metal-archives-entry-artist entry)
(metal-archives-entry-album entry)
(metal-archives-entry-type entry)
(metal-archives-entry-genre entry)
(org-read-date nil nil (metal-archives-entry-date entry) nil))))
(insert org-entry)))
(defun metal-archives-org-generate-org-from-db ()
"Generate the `org-agenda' buffer and update the global agenda using the entry database."
(interactive)
(let* ((coding-system-for-write 'utf-8))
(with-current-buffer (find-file metal-archives-org-target-file)
;; Clean
(erase-buffer)
;; Synchronize db and the file
(mapc 'metal-archives-org~format-entry metal-archives-entry-database)
;; Save the buffer
(save-buffer)
;; Move back to previous buffer
(switch-to-buffer (other-buffer (current-buffer) 1)))))
(provide 'metal-archives-org)
;;; metal-archives-org.el ends here