emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 5d9f1992e9 1/2: Rework denote--filetype-heuristi


From: ELPA Syncer
Subject: [elpa] externals/denote 5d9f1992e9 1/2: Rework denote--filetype-heuristics
Date: Sun, 21 Aug 2022 11:57:28 -0400 (EDT)

branch: externals/denote
commit 5d9f1992e93fceee57a498c9ba0b937cdc29c33d
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>

    Rework denote--filetype-heuristics
    
    denote--filetype-heuristics should always return an md filetype if the
    file extension is md even if no key regexps match in the file. In that
    case, we use the first md type in denote-file-types.
    
    markdown-yaml should appear before markdown-toml in denote-file-types
    because it used to be the default markdown type of
    denote--filetype-heuristics.
---
 denote.el | 50 ++++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/denote.el b/denote.el
index 780081a4dd..f310a81e17 100644
--- a/denote.el
+++ b/denote.el
@@ -665,22 +665,22 @@ identifier: %s
      :keywords-key-regexp "^#\\+filetags\\s-*:"
      :keywords-value-function denote--format-keywords-for-org-front-matter
      :keywords-value-reverse-function 
denote--extract-keywords-from-front-matter)
-    (markdown-toml
+    (markdown-yaml
      :extension ".md"
-     :front-matter ,denote-toml-front-matter
-     :title-key-regexp "^title\\s-*="
+     :front-matter ,denote-yaml-front-matter
+     :title-key-regexp "^title\\s-*:"
      :title-value-function denote--surround-with-quotes
      :title-value-reverse-function denote--trim-whitespace-then-quotes
-     :keywords-key-regexp "^tags\\s-*="
+     :keywords-key-regexp "^tags\\s-*:"
      :keywords-value-function denote--format-keywords-for-md-front-matter
      :keywords-value-reverse-function 
denote--extract-keywords-from-front-matter)
-    (markdown-yaml
+    (markdown-toml
      :extension ".md"
-     :front-matter ,denote-yaml-front-matter
-     :title-key-regexp "^title\\s-*:"
+     :front-matter ,denote-toml-front-matter
+     :title-key-regexp "^title\\s-*="
      :title-value-function denote--surround-with-quotes
      :title-value-reverse-function denote--trim-whitespace-then-quotes
-     :keywords-key-regexp "^tags\\s-*:"
+     :keywords-key-regexp "^tags\\s-*="
      :keywords-value-function denote--format-keywords-for-md-front-matter
      :keywords-value-reverse-function 
denote--extract-keywords-from-front-matter)
     (text
@@ -1263,23 +1263,29 @@ See the format of `denote-file-types'."
 (defun denote--filetype-heuristics (file)
   "Return likely file type of FILE.
 Use the file extension to detect the file type of the file.
-If more than one file type correspond to this file extension,
-use the first file type for which the key-title-kegexp matches
-in the file.
-Else, if nothing works, the file type is assumed to be the first
-in `denote-file-types'."
+
+If more than one file type correspond to this file extension, use
+the first file type for which the key-title-kegexp matches in the
+file or, if none matches, use the first type with this file
+extension in `denote-file-type'.
+
+If no file types in `denote-file-types' has the file extension,
+the file type is assumed to be the first of `denote-file-types'."
   (let* ((file-type)
          (extension (file-name-extension file t))
          (types (denote--file-types-with-extension extension)))
-    (if (= (length types) 1)
-        (setq file-type (caar types))
-      (when-let ((found-type (seq-find
-                              (lambda (type)
-                                (denote--regexp-in-file-p (plist-get (cdr 
type) :title-key-regexp) file))
-                              types)))
-        (setq file-type (car found-type))))
-    (unless file-type
-      (setq file-type (caar denote-file-types)))
+    (cond ((not types)
+           (setq file-type (caar denote-file-types)))
+          ((= (length types) 1)
+           (setq file-type (caar types)))
+          (t
+           (if-let ((found-type
+                     (seq-find
+                      (lambda (type)
+                        (denote--regexp-in-file-p (plist-get (cdr type) 
:title-key-regexp) file))
+                      types)))
+               (setq file-type (car found-type))
+             (setq file-type (caar types)))))
     file-type))
 
 (defun denote--file-attributes-time (file)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]