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

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

[elpa] externals/denote a44600b4fa 11/19: Refactor denote-retrieve-filen


From: ELPA Syncer
Subject: [elpa] externals/denote a44600b4fa 11/19: Refactor denote-retrieve-filename-title
Date: Sat, 2 Dec 2023 03:57:53 -0500 (EST)

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

    Refactor denote-retrieve-filename-title
    
    We now return an empty string if no title is present. This makes the
    behaviour consistent with 'denote-retrieve-filename-keywords' and
    'denote-retrieve-filename-signature'.
    
    The use of 'file-name-base' is now subject to a non-nil optional
    argument. This makes it easier for the caller to handle cases as they
    see fit.
---
 README.org | 14 +++++++++-----
 denote.el  | 28 ++++++++++++++++++----------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/README.org b/README.org
index 260a80dec6..f435a1d08e 100644
--- a/README.org
+++ b/README.org
@@ -3905,15 +3905,19 @@ might change them without further notice.
   ~denote-create-unique-file-identifier~ function.
 
 #+findex: denote-retrieve-filename-title
-+ Function ~denote-retrieve-filename-title~ :: Extract title from
-  =FILE= name, else return ~file-name-base~.  Run ~denote-desluggify~
-  on the title if the extraction is successful.
++ Function ~denote-retrieve-filename-title~ ::  Extract Denote title
+  component from =FILE= name, else return an empty string. With
+  optional =FILE-NAME-BASE-FALLBACK= return ~file-name-base~ if no
+  Denote title component exists. If the extraction is succcessful
+  (when no ~file-name-base~ is involved) run ~denote-desluggify~ on
+  the title. [ Revised as part of {{{development-version}}} to return
+  an empty string if no title is present and to make the use of
+  ~file-name-base~ optional. ]
 
 #+findex: denote-retrieve-filename-keywords
 + Function ~denote-retrieve-filename-keywords~ ::  Extract keywords
   from =FILE= name, if present, else return an empty string. Return
-  matched keywords as a single string. [ Part of
-  {{{development-version}}} . ]
+  matched keywords as a single string. [ Part of {{{development-version}}} . ]
 
 #+findex: denote-retrieve-filename-signature
 + Function ~denote-retrieve-filename-signature~ :: Extract signature
diff --git a/denote.el b/denote.el
index 93cb46b8e4..86157b5343 100644
--- a/denote.el
+++ b/denote.el
@@ -1415,15 +1415,23 @@ Return matched keywords as a single string."
         (match-string 1 filename)
       "")))
 
-(defun denote-retrieve-filename-title (file)
-  "Extract title from FILE name, else return `file-name-base'.
-Run `denote-desluggify' on title if the extraction is sucessful."
-  (if-let (((file-exists-p file))
-           ((denote-file-has-identifier-p file))
-           ((string-match denote-title-regexp file))
-           (title (match-string 1 file)))
-      (denote-desluggify title)
-    (file-name-base file)))
+(defun denote-retrieve-filename-title (file &optional file-name-base-fallback)
+  "Extract Denote title component from FILE name, else return an empty string.
+
+With optional FILE-NAME-BASE-FALLBACK return `file-name-base' if
+no Denote title component exists.
+
+If the extraction is succcessful (when no `file-name-base' is
+involved) run `denote-desluggify' on the title"
+  (unless (file-exists-p file)
+    (error "%s does not exist as a file" file))
+  (cond
+   ((and (denote-file-has-identifier-p file)
+         (string-match denote-title-regexp file))
+    (denote-desluggify (match-string 1 file)))
+   (file-name-base-fallback
+    (file-name-base file))
+   (t "")))
 
 (defun denote--file-with-temp-buffer-subr (file)
   "Return path to FILE or its buffer together with the appropriate function.
@@ -1496,7 +1504,7 @@ that internally)."
            (title (denote-retrieve-title-value file type))
            ((not (string-blank-p title))))
       title
-    (denote-retrieve-filename-title file)))
+    (denote-retrieve-filename-title file :file-name-base-as-fallback)))
 
 (defun denote--retrieve-location-in-xrefs (identifier)
   "Return list of xrefs for IDENTIFIER with their respective location.



reply via email to

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