branch: externals/denote
commit 7bb8b7c4366c0ef276a93c8310ff2b00083e0eaa
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Make denote-rename-buffer-format accept human-readable date and "do what I 
mean" specifiers
---
 README.org | 22 +++++++++++++++++-----
 denote.el  | 24 ++++++++++++++++++++----
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/README.org b/README.org
index 3c941d7eb0..cb07e3aecb 100644
--- a/README.org
+++ b/README.org
@@ -3346,6 +3346,9 @@ available to all programs.
 :CUSTOM_ID: h:35507c18-35b1-41b9-9d80-52f54fcef3cb
 :END:
 
+[ Updated as part of {{{development-version}}} to use a default "do
+  what I mean" value. ]
+
 The user option ~denote-rename-buffer-format~ controls how the
 function ~denote-rename-buffer~ chooses the name of the
 buffer-to-be-renamed.
@@ -3355,9 +3358,15 @@ are placeholders for Denote file name components 
([[#h:4e9c7512-84dc-4dfb-9fa9-e
 
 #+vindex: denote-rename-buffer-backlinks-indicator
 - The =%t= is the Denote =TITLE= in the front matter or the file name.
-- The =%T= is the Denote =TITLE= in the file name. [ The =%T= is part of 
{{{development-version}}}. ]
+- The =%T= is the Denote =TITLE= in the file name. [ The =%T= is part
+  of {{{development-version}}}. ]
 - The =%i= is the Denote =IDENTIFIER= of the file.
+- The =%I= is the identifier converted to =DAYNAME, DAYNUM MONTHNUM
+  YEAR=. [ The =%I= is part of {{{development-version}}}. ]
 - The =%d= is the same as =%i= (=DATE= mnemonic).
+- The =%D= is a "do what I mean" which behaves the same as =%t= and if
+  that returns nothing, it falls back to =%I=, then =%i=. [ The =%D=
+  is part of {{{development-version}}}. ]
 - The =%s= is the Denote =SIGNATURE= of the file.
 - The =%k= is the Denote =KEYWORDS= of the file.
 - The =%b= is an indicator of whether or not the file has backlinks
@@ -3384,9 +3393,12 @@ include some text that makes Denote buffers stand out, 
such as
 a =[D]= prefix.  Examples:
 
 #+begin_src emacs-lisp
-;; Use a literal [D] prefix, followed by the title and then the
-;; backlinks indicator (default).
-(setq denote-rename-buffer-format "[D] %t%b")
+;; The following is the default value.  Use a literal [D] prefix,
+;; followed by the title and then the backlinks indicator.  If there
+;; is no title, use the identifier in its human-readable date
+;; representation, and if that is not possible, use the identifier
+;; as-is.
+(setq denote-rename-buffer-format "[D] %D%b")
 
 ;; Customize what the backlink indicator looks like.  This two-faced
 ;; arrow is the default.
@@ -3400,7 +3412,7 @@ a =[D]= prefix.  Examples:
 (setq denote-rename-buffer-format "[D] %t")
 
 ;; As above, but also add the `denote-rename-buffer-backlinks-indicator' at 
the end.
-(setq denote-rename-buffer-format "[D] %t")
+(setq denote-rename-buffer-format "[D] %t%b")
 #+end_src
 
 Users who need yet more flexibility are best served by writing their
diff --git a/denote.el b/denote.el
index 7d4e4c1c2b..28f4cd2b12 100644
--- a/denote.el
+++ b/denote.el
@@ -6262,15 +6262,17 @@ option `denote-templates'."
   :package-version '(denote . "3.1.0")
   :group 'denote-rename-buffer)
 
-(defcustom denote-rename-buffer-format "[D] %t%b"
+(defcustom denote-rename-buffer-format "[D] %D%b"
   "The format of the buffer name `denote-rename-buffer' should use.
-The value is a string that treats specially the following
-specifiers:
+The value is a string that treats specially the following specifiers:
 
 - The %t is the Denote TITLE in the front matter or the file name.
 - The %T is the Denote TITLE in the file name.
 - The %i is the Denote IDENTIFIER of the file.
+- The %I is the identifier converted to DAYNAME, DAYNUM MONTHNUM YEAR.
 - The %d is the same as %i (DATE mnemonic).
+- The %D is a \"do what I mean\" which behaves the same as %t and if
+  that returns nothing, it falls back to %I, then %i.
 - The %s is the Denote SIGNATURE of the file.
 - The %k is the Denote KEYWORDS of the file.
 - The %b inserts `denote-rename-buffer-backlinks-indicator'.
@@ -6293,7 +6295,7 @@ Any other string it taken as-is.  Users may want, for 
example, to
 include some text that makes Denote buffers stand out, such as
 a [D] prefix."
   :type 'string
-  :package-version '(denote . "3.1.0")
+  :package-version '(denote . "4.0.0")
   :group 'denote-rename-buffer)
 
 (defcustom denote-rename-buffer-function #'denote-rename-buffer
@@ -6329,7 +6331,21 @@ buffer will be used, if available."
                           (cons ?T (or (denote-retrieve-filename-title file) 
""))
                           (cons ?b (if should-show-backlink-indicator 
denote-rename-buffer-backlinks-indicator ""))
                           (cons ?i (or (denote-retrieve-filename-identifier 
file) ""))
+                          ;; TODO 2025-04-03: Maybe we can have something like 
`denote-date-format' here,
+                          ;; but I think we are okay with a hardcoded value.
+                          (cons ?I (or (when-let* ((id 
(denote-retrieve-filename-identifier file))
+                                                   (_ (denote-valid-date-p 
id)))
+                                         (format-time-string "%A, %e %B %Y" 
(date-to-time (denote--id-to-date id))))
+                                       ""))
                           (cons ?d (or (denote-retrieve-filename-identifier 
file) ""))
+                          (cons ?D (cond
+                                    ((denote-retrieve-front-matter-title-value 
file type))
+                                    ((denote-retrieve-filename-title file))
+                                    ((when-let* ((id 
(denote-retrieve-filename-identifier file)))
+                                       (if (denote-valid-date-p id)
+                                           (format-time-string "%A, %e %B %Y" 
(date-to-time (denote--id-to-date id)))
+                                         id)))
+                                    (t  "")))
                           (cons ?s (or (denote-retrieve-filename-signature 
file) ""))
                           (cons ?k (or (denote-retrieve-filename-keywords 
file) ""))
                           (cons ?% "%"))

Reply via email to