protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme

Home Page:https://protesilaos.com/emacs/denote

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`denote-extract-filename-title` (simpler/minimal version of `denote-retrieve-filename-title`)

mentalisttraceur opened this issue · comments

I have found this function helpful to have around when building things on top of Denote:

(defun denote-extract-title-slug-from-path (path)
    (let ((file (file-name-nondirectory path)))
        (string-match denote-title-regexp file)
        (match-string 1 file)))

I find this more helpful than denote-retrieve-filename-title because

  1. it doesn't require the file to exist on the file system - it's simply looking at the path string, and

  2. in situations where my code gets the title from the file name, I'd rather see the title as-is, because in those use-cases the slug is more "true"/"real" than the desluggified string.

Sharing it here in case it helps someone else. You are of course welcome to upstream it.

Your function and denote-retrieve-filename-title have the same implementations. Maybe you meant to share something else?

Maybe you changed it since last stable release. I didn't check, because to a user, Denote is and does whatever you last released, and because the modern Github interface is off-puttingly/demotivatingly slow/laggy.

I'll check after I finish typing this comment.

Here's the definition my Emacs finds in the 2.2.4 version of Denote I got from ELPA:

(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 "")))

It has several differences - salient of them: error if the file does not exist, and desluggifying.

Ah, yep, since last release it was changed to exactly what I describe here. Nice+thanks!

No problem!

Yes, it changed a while ago, but it has been a while since the last release. This function with the desluggification still exists in the form of denote--retrieve-title-or-filename.