fix(denote-get-path-by-id): #135

Reference: https://github.com/protesilaos/denote/issues/135

This patch change function 'denote-get-path-by-id' to allow for the following:

- A single ID points to multiple files with different extensions
- Denote needs to find a single file out of the multiple files
- This is not necessarily a user error (export an Org file to an HTML)
- Denote should let user decide their "primary" file extension

The case the patch is intended to fix goes something like this:

- You have 20230216__mynotes--tag.org.
- You export it to 20230216__mynotes--tag.html.
- Both files are in denote-directory
- This means you have two files with the same ID with different
  extensions denote-link-find-file, denote-link-find-backlink, and xref
  integration might find the html file INSTEAD OF the .org file

This is because html is earlier in the alphabetical order than
org. Because the function uses seq-find, it will find the .html file
first and returns it.
This commit is contained in:
Noboru Ota 2023-03-05 22:14:15 +01:00 committed by Protesilaos Stavrou
parent 29680f9583
commit 9ce9a245cc
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA

View file

@ -730,11 +730,17 @@ whatever matches `denote-excluded-directories-regexp'."
(defun denote-get-path-by-id (id)
"Return absolute path of ID string in `denote-directory-files'."
(seq-find
(lambda (file)
(and (denote-file-has-identifier-p file)
(string-prefix-p id (file-name-nondirectory file))))
(denote-directory-files)))
(let ((files
(seq-filter
(lambda (file)
(and (denote-file-has-identifier-p file)
(string-prefix-p id (file-name-nondirectory file))))
(denote-directory-files))))
(if (length< files 2) (car files)
(seq-find (lambda (file) (and (denote-file-is-note-p file)
(or (string= denote-file-type (file-name-extension file))
(string= "org" (file-name-extension file)))))
files))))
(define-obsolete-function-alias
'denote--get-note-path-by-id