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.
This commit is contained in:
Protesilaos Stavrou 2023-12-02 08:44:05 +02:00
parent b13d899c01
commit a44600b4fa
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 27 additions and 15 deletions

View file

@ -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

View file

@ -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.