branch: externals/denote
commit 301575c318194a2edaec50ed1adc5839d9c61cd2
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>
Add another condition to denote-file-type to fall back to user's preferred
file type
---
denote.el | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/denote.el b/denote.el
index 196fe22f44..011708a460 100644
--- a/denote.el
+++ b/denote.el
@@ -3826,14 +3826,22 @@ matches in the file.
Return nil if the file type is not recognized."
(when-let* ((extension (denote-get-file-extension-sans-encryption file))
- (types (denote--file-types-with-extension extension)))
- (if (= (length types) 1)
- (caar types)
- (or (car (seq-find
- (lambda (type)
- (denote--regexp-in-file-p (plist-get (cdr type)
:title-key-regexp) file))
- types))
- (caar types)))))
+ (types (denote--file-types-with-extension extension))
+ (length (length types)))
+ (cond
+ ((= length 1)
+ (caar types))
+ ((car (seq-find
+ (lambda (type)
+ (denote--regexp-in-file-p (plist-get (cdr type)
:title-key-regexp) file))
+ types)))
+ ;; If the user has picked something like `markdown-toml' and this
+ ;; is an ".md" file, we can fall back to this.
+ ((and (> length 1)
+ (memq denote-file-type (mapcar #'car types)))
+ denote-file-type)
+ (t
+ (caar types)))))
(defun denote-filetype-heuristics (file)
"Return likely file type of FILE.