protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
541 stars 55 forks source link

denote-file-types: lack of :date-key-regexp and :identifier-key-regexp #467

Closed sarcom-sar closed 1 month ago

sarcom-sar commented 1 month ago

Hey, I've began hacking a bit on denote and started wondering why there are no keywords for :date-key-regexp and :identifier-key-regexp in denote-file-types, but there are for :title-key-regexp and :keywords-key-regexp.

Is it a "political" decision, because ID can be easily found in filename, while the date would be a huge pain?

As for proposed implementation :identifier-key-reverse-function the defun for :title-key-reverse-function could be easily reused, while the date would need something akin to:

;; example for org
(defun denote-extract-org-date-from-front-matter (string)
  (org-read-date nil t string nil))

Sadly, this implies at least three separate functions, which might be smelly, but since we have denote-date-foo, where foo is rfc3339, iso-8601 or org-timestamp, it would still be symetrical.

jeanphilippegg commented 1 month ago

The reason they were not added was that we had no use for them yet.

However, I agree that we should probably include them all. This will make denote-file-types bigger, but this is not really an issue.

We want to include the signature in the front matter (see #366). We will need to add the relevant functions for signature at some point. The other functions would also be necessary if we allow changing the identifier/date under some conditions.

I am curious: What is your use-case for them?

sarcom-sar commented 1 month ago

What is your use-case for them?

Retrieval of :date-key-regexp et al. and :identifier-key-regexp et al. would be useful when working with individual notes downstream. To be precise, it would allow to elegantly pattern match elements according to needs, like:

(let ((foo (pcase some-keyword
         ('title :title-key-regexp)
         ;; you know the rest
         ('identifier :identifier-key-regexp)
         (_ nil)))
      (file-type (denote-filetype-heuristics file)))
  (unless foo
    (re-search-forward (plist-get foo file-type) nil t)))

The other functions would also be necessary if we allow changing the identifier/date under some conditions.

To be honest, I now understand the approach to denote-file-types better. The mutable parts are retrievable from front-matter, while non-mutable parts are not. Under my understanding the :date-function made more sense as part of :date-key-regexp et al. but now I understand the code's approach.

Edit: sorry for closing and reopening, this was a missed mouse input.

protesilaos commented 1 month ago

I just merged the PR of @jeanphilippegg. Thank you @sarcom-sar for the discussion! Closing now.