-
Notifications
You must be signed in to change notification settings - Fork 1
/
zettel2-frontmatter.el
80 lines (56 loc) · 2.3 KB
/
zettel2-frontmatter.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
;;; zettel2-frontmatter.el --- Frontmatter templates for zettel2 -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Wojciech Siewierski
;; Author: Wojciech Siewierski
;; Keywords: outlines, org-mode, convenience
;; Version: 0.9
;; This program 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 of the License, or
;; (at your option) any later version.
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Frontmatter templates for zettel2.
;;; Code:
(require 'org)
(defgroup zettel2-frontmatter nil
"Frontmatter templates for zettel2."
:group 'zettel2)
(defconst zettel2-frontmatter-simple "#+TITLE: %t\n\n")
(defconst zettel2-frontmatter-with-id "\
:PROPERTIES:
:ID: %i
:END:
#+TITLE: %t
"
"Compatible with `org-mode' IDs, but might break the `deft' title detection.")
(defconst zettel2-frontmatter-with-date "\
#+TITLE: %t
#+DATE: %d
"
"A human readable date.
Duplicated from the ID in the filename for the user convenience.")
(defcustom zettel2-frontmatter-template zettel2-frontmatter-simple
"The frontmatter template passed to `format-spec'.
%i is replaced with the note ID.
%t is replaced with the note title.
%d is replaced with the note creation date.
Not all identifiers need to be used, but setting the title is
highly recommended."
:type `(choice
(const :tag "Simple" ,zettel2-frontmatter-simple)
(const :tag "With ID" ,zettel2-frontmatter-with-id)
(const :tag "With date" ,zettel2-frontmatter-with-date)
(string :tag "Custom")))
(defun zettel2-frontmatter-format-spec (id title &optional time)
"Generate the alist for `format-spec'.
ID, TITLE and TIME are the corresponding metadata of the file."
`((?i . ,id)
(?t . ,title)
(?d . ,(format-time-string (org-time-stamp-format) time))))
(provide 'zettel2-frontmatter)
;;; zettel2-frontmatter.el ends here