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

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

[elpa] externals/denote a204554b8d 05/17: denote-get-identifier returns


From: ELPA Syncer
Subject: [elpa] externals/denote a204554b8d 05/17: denote-get-identifier returns an empty string when date is nil
Date: Sun, 10 Nov 2024 00:57:51 -0500 (EST)

branch: externals/denote
commit a204554b8d667781881c13b356cd32639d57b96c
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>

    denote-get-identifier returns an empty string when date is nil
    
    Also make the date parameter mandatory
---
 README.org           |  4 ++--
 denote.el            | 19 ++++++++++---------
 tests/denote-test.el |  6 ++----
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/README.org b/README.org
index 574b3df034..419c450880 100644
--- a/README.org
+++ b/README.org
@@ -5775,8 +5775,8 @@ might change them without further notice.
 
 #+findex: denote-get-identifier
 + Function ~denote-get-identifier~ :: Convert =DATE= into a Denote
-  identifier using ~denote-id-format~. =DATE= is parsed by
-  ~denote-valid-date-p~. If =DATE= is nil, use the current time.
+  identifier using ~denote-id-format~. If =DATE= is nil, return an empty
+  string as the identifier.
 
 #+findex: denote-create-unique-file-identifier
 + Function ~denote-create-unique-file-identifier~ :: Create a new unique
diff --git a/denote.el b/denote.el
index 37af20db03..92e705ae02 100644
--- a/denote.el
+++ b/denote.el
@@ -1867,13 +1867,12 @@ To create a new one, refer to the function
   (or (denote-retrieve-filename-identifier file)
       (error "Cannot find `%s' as a file with a Denote identifier" file)))
 
-(defun denote-get-identifier (&optional date)
+(defun denote-get-identifier (date)
   "Convert DATE into a Denote identifier using `denote-id-format'.
-DATE is parsed by `denote-valid-date-p'.  If DATE is nil, use the
-current time."
-  (format-time-string
-   denote-id-format
-   (when date (denote-valid-date-p date))))
+If DATE is nil, return an empty string as the identifier."
+  (if date
+      (format-time-string denote-id-format date)
+    ""))
 
 (defvar denote--used-ids nil
   "Hash table of used identifiers.
@@ -1899,7 +1898,7 @@ To only return an existing identifier, refer to the 
function
   (let ((id (cond
              (date (denote-get-identifier date))
              ((denote--file-attributes-time file))
-             (t (denote-get-identifier)))))
+             (t (denote-get-identifier (current-time))))))
     (denote--find-first-unused-id id)))
 
 (defun denote-retrieve-filename-keywords (file)
@@ -2653,7 +2652,7 @@ Use Org's more advanced date selection utility if the 
user option
 
 (defun denote-prompt-for-date-return-id ()
   "Use `denote-date-prompt' and return it as `denote-id-format'."
-  (denote-get-identifier (denote-date-prompt)))
+  (denote-get-identifier (denote-valid-date-p (denote-date-prompt))))
 
 (defvar denote-subdirectory-history nil
   "Minibuffer history of `denote-subdirectory-prompt'.")
@@ -2926,7 +2925,9 @@ Org.  Otherwise, use the function `denote-file-type' to 
return the type."
 
 (defun denote--file-attributes-time (file)
   "Return `file-attribute-modification-time' of FILE as identifier."
-  (denote-get-identifier (file-attribute-modification-time (file-attributes 
file))))
+  (when-let* ((file-modification-time
+               (file-attribute-modification-time (file-attributes file))))
+    (denote-get-identifier file-modification-time)))
 
 (defun denote--revert-dired (buf)
   "Revert BUF if appropriate.
diff --git a/tests/denote-test.el b/tests/denote-test.el
index 823daf0674..10c24e9647 100644
--- a/tests/denote-test.el
+++ b/tests/denote-test.el
@@ -395,11 +395,9 @@ does not involve the time zone."
 
 (ert-deftest denote-test--denote-get-identifier ()
   "Test that `denote-get-identifier' returns an identifier."
-  (should (and (equal (denote-get-identifier) (format-time-string 
denote-id-format (current-time)))
-               (equal (denote-get-identifier "2024-02-01 10:34") 
"20240201T103400")
+  (should (and (equal (denote-get-identifier nil) "")
                (equal (denote-get-identifier 1705644188) "20240119T080308")
-               (equal (denote-get-identifier '(26026 4251)) 
"20240119T080307")))
-  (should-error (denote-get-identifier "Invalid date")))
+               (equal (denote-get-identifier '(26026 4251)) 
"20240119T080307"))))
 
 (ert-deftest denote-test--denote-retrieve-filename-identifier ()
   "Test that `denote-retrieve-filename-identifier' returns only the 
identifier."



reply via email to

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