branch: externals/denote commit 9bf10437e0e8211622e9e5e5dbce6eac29b17f0d Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Add denote-front-matter-date-format user option Thanks to Kaushal Modi for proposing the use of an Org timestamp. (It was done via email and this information is shared with permission.) --- README.org | 14 ++++++++++++++ denote.el | 30 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 05b781e299..265804d15b 100644 --- a/README.org +++ b/README.org @@ -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) @@ -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 diff --git a/denote.el b/denote.el index 6f5e47c862..6a4a911aa3 100644 --- a/denote.el +++ b/denote.el @@ -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" @@ -288,6 +306,16 @@ 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'." @@ -295,7 +323,7 @@ Use optional PATH, else create it with `denote--path'." (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))