emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote dec6367e64 2/5: Make denote-file-types read a :d


From: ELPA Syncer
Subject: [elpa] externals/denote dec6367e64 2/5: Make denote-file-types read a :date-function
Date: Sun, 30 Oct 2022 00:57:36 -0400 (EDT)

branch: externals/denote
commit dec6367e6443e8b5263a072ad3f8f80fdde4c294
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Make denote-file-types read a :date-function
    
    The end goal is to make this variable the single point of entry to all
    file-type-aware operations.  This way, expert users can add support
    for any file type they want.  Depending on how it goes, we may even
    make it a user option.
    
    Relevant thread on the GitHub mirror issue 86:
    <https://github.com/protesilaos/denote/issues/86>.
---
 README.org | 21 +++++++++++++--------
 denote.el  | 23 +++++++++++++++++------
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/README.org b/README.org
index e5034e8a9e..1f29682f85 100644
--- a/README.org
+++ b/README.org
@@ -2639,36 +2639,41 @@ might change them without further notice.
   =PROPERTY-LIST= is a plist that consists of eight elements:
 
   1. =:extension= which is a string with the file extension
-     including the perion.
+     including the period.
 
-  2. =:front-matter= which is either a string passed to ~format~ or a
+  2. ~:date-function~ is a function that can format a date.  See the
+     functions ~denote--date-iso-8601~, ~denote--date-rfc3339~, and
+     ~denote--date-org-timestamp~. [This property is part of
+     {{{development-version}}}.]
+
+  3. =:front-matter= which is either a string passed to ~format~ or a
      variable holding such a string.  The ~format~ function accepts four
      arguments, which come from ~denote~ in this order: =TITLE=, =DATE=,
      =KEYWORDS=, =IDENTIFIER=.  Read the doc string of ~format~ on how
      to reorder arguments.
 
-  3. =:title-key-regexp= is a string with the regular expression that is
+  4. =:title-key-regexp= is a string with the regular expression that is
      used to retrieve the title line in a file.  The first line matching
      this regexp is considered the title line.
 
-  4. =:title-value-function= is the function used to format the raw
+  5. =:title-value-function= is the function used to format the raw
      title string for inclusion in the front matter (e.g. to surround it
      in quotes).  Use the ~identity~ function if no further processing
      is required.
 
-  5. =:title-value-reverse-function= is the function used to retrieve
+  6. =:title-value-reverse-function= is the function used to retrieve
      the raw title string from the front matter.  It performs the
      reverse of =:title-value-function=.
 
-  6. =:keywords-key-regexp= is a string with the regular expression used
+  7. =:keywords-key-regexp= is a string with the regular expression used
      to retrieve the keywords' line in the file.  The first line
      matching this regexp is considered the keywords' line.
 
-  7. =:keywords-value-function= is the function used to format the
+  8. =:keywords-value-function= is the function used to format the
      keywords' list of strings as a single string for inclusion in the
      front matter.
 
-  8. =:keywords-value-reverse-function= is the function used to retrieve
+  9. =:keywords-value-reverse-function= is the function used to retrieve
      the keywords' value from the front matter.  It performs the reverse
      of the =:keywords-value-function=.
 
diff --git a/denote.el b/denote.el
index 49269f5c19..40a0855694 100644
--- a/denote.el
+++ b/denote.el
@@ -876,6 +876,7 @@ Consult the `denote-file-types' for how this is used."
 (defvar denote-file-types
   '((org
      :extension ".org"
+     :date-function denote--date-org-timestamp
      :front-matter denote-org-front-matter
      :title-key-regexp "^#\\+title\\s-*:"
      :title-value-function identity
@@ -885,6 +886,7 @@ Consult the `denote-file-types' for how this is used."
      :keywords-value-reverse-function 
denote-extract-keywords-from-front-matter)
     (markdown-yaml
      :extension ".md"
+     :date-function denote--date-rfc3339
      :front-matter denote-yaml-front-matter
      :title-key-regexp "^title\\s-*:"
      :title-value-function denote-surround-with-quotes
@@ -894,6 +896,7 @@ Consult the `denote-file-types' for how this is used."
      :keywords-value-reverse-function 
denote-extract-keywords-from-front-matter)
     (markdown-toml
      :extension ".md"
+     :date-function denote--date-rfc3339
      :front-matter denote-toml-front-matter
      :title-key-regexp "^title\\s-*="
      :title-value-function denote-surround-with-quotes
@@ -903,6 +906,7 @@ Consult the `denote-file-types' for how this is used."
      :keywords-value-reverse-function 
denote-extract-keywords-from-front-matter)
     (text
      :extension ".txt"
+     :date-function denote--date-iso-8601
      :front-matter denote-text-front-matter
      :title-key-regexp "^title\\s-*:"
      :title-value-function identity
@@ -918,7 +922,11 @@ one of those specified in `denote-file-type'.
 PROPERTY-LIST is a plist that consists of 8 elements:
 
 - `:extension' which is a string with the file extension
-  including the perion.
+  including the period.
+
+- `:date-function' is a function that can format a date.  See the
+  functions `denote--date-iso-8601', `denote--date-rfc3339', and
+  `denote--date-org-timestamp'.
 
 - `:front-matter' which is either a string passed to `format' or
   a variable holding such a string.  The `format' function
@@ -954,6 +962,12 @@ PROPERTY-LIST is a plist that consists of 8 elements:
 If `denote-file-type' is nil, we use the first element of this
 list for new note creation.  The default is `org'.")
 
+(defun denote--date-format-function (file-type)
+  "Return date format function of FILE-TYPE."
+  (plist-get
+   (alist-get file-type denote-file-types)
+   :date-function))
+
 (defun denote--file-extension (file-type)
   "Return file type extension based on FILE-TYPE."
   (plist-get
@@ -1283,11 +1297,8 @@ provided by `denote'.  FILETYPE is one of the values of
     (cond
      ((stringp format)
       (format-time-string format date))
-     ((or (eq file-type 'markdown-toml)
-          (eq file-type 'markdown-yaml))
-      (denote--date-rfc3339 date))
-     ((eq file-type 'text)
-      (denote--date-iso-8601 date))
+     ((when-let ((fn (denote--date-format-function file-type)))
+        (funcall fn date)))
      (t
       (denote--date-org-timestamp date)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]