Skip to content

Commit

Permalink
Add denote-front-matter-date-format user option
Browse files Browse the repository at this point in the history
Thanks to Kaushal Modi for proposing the use of an Org timestamp.  (It
was done via email and this information is shared with permission.)
  • Loading branch information
protesilaos committed Jun 8, 2022
1 parent bf342a1 commit 9bf1043
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,13 @@ Everything is in place to set up the package.
#+begin_src emacs-lisp
(require 'denote)

;; Remember to check the doc strings of those variables.
(setq denote-directory (expand-file-name "~/Documents/notes/"))
(setq denote-known-keywords
'("emacs" "philosophy" "politics" "economics"))
(setq denote-infer-keywords t)
(setq denote-sort-keywords t)
(setq denote-front-matter-date-format 'org-timestamp)

(require 'denote-link)
(require 'denote-dired)
Expand All @@ -358,6 +360,18 @@ Everything is in place to set up the package.
:jump-to-captured t))))
#+end_src

* Acknowledgements
:PROPERTIES:
:CUSTOM_ID: h:f8126820-3b59-49fa-bcc2-73bd60132bb9
:END:
#+cindex: Contributors

Denote is meant to be a collective effort. Every bit of help matters.

+ Author/maintainer :: Protesilaos Stavrou.

+ Ideas and/or user feedback :: Kaushal Modi.

* GNU Free Documentation License
:PROPERTIES:
:APPENDIX: t
Expand Down
30 changes: 29 additions & 1 deletion denote.el
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ If nil, show the keywords in their given order."
:group 'denote
:type 'boolean)

(defcustom denote-front-matter-date-format nil
"Date format in the front matter (file header) of new notes.
If the value is nil, use a plain date in YEAR-MONTH-DAY notation,
like 2022-06-08.
If the value is the `org-timestamp' symbol, format the date as an
inactive Org timestamp such as: [2022-06-08 Wed 06:19].
If a string, use it as the argument of `format-time-string'.
Read the documentation of that function for valid format
specifiers."
:type '(choice
(const :tag "Just the date like 2022-06-08" nil)
(const :tag "An inactive Org timestamp like [2022-06-08 Wed 06:19]" org-timestamp)
(string :tag "Custom format for `format-time-string'"))
:group 'denote)

;;;; Main variables

(defconst denote--id "%Y%m%d_%H%M%S"
Expand Down Expand Up @@ -288,14 +306,24 @@ Format current time, else use optional ID."
keywords
(denote--sluggify title))))

(defun denote--date ()
"Expand the date for a new note's front matter."
(let ((format denote-front-matter-date-format))
(cond
((eq format 'org-timestamp)
(format-time-string "[%F %a %R]"))
((stringp format)
(format-time-string format))
(t (format-time-string "%F")))))

(defun denote--prepare-note (title keywords &optional path)
"Use TITLE and KEYWORDS to prepare new note file.
Use optional PATH, else create it with `denote--path'."
(let* ((p (or path (denote--path title keywords)))
(default-directory denote-directory)
(buffer (unless path (find-file p)))
(header (denote--file-meta-header
title (format-time-string "%F") keywords p
title (denote--date) keywords p
(format-time-string denote--id))))
(unless path
(with-current-buffer buffer (insert header))
Expand Down

0 comments on commit 9bf1043

Please sign in to comment.