branch: externals/denote commit df44843766cbb9519d853fdaf7013a31528c79e5 Author: Jean-Philippe Gagné Guay <jeanphilippe...@gmail.com> Commit: Jean-Philippe Gagné Guay <jeanphilippe...@gmail.com>
Make denote-filetype-heuristics return nil with unrecognized file types --- README.org | 3 +-- denote.el | 24 ++++++++++-------------- tests/denote-test.el | 3 +-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/README.org b/README.org index 12fe793d89..154005c4b6 100644 --- a/README.org +++ b/README.org @@ -4298,8 +4298,7 @@ might change them without further notice. the first file type for which the :title-key-regexp in ~denote-file-types~ matches in the file. - If no file type in ~denote-file-types~ has the file extension, the - file type is assumed to be the first one in ~denote-file-types~. + Return nil if the file type is not recognized. #+findex: denote-format-file-name + Function ~denote-format-file-name~ :: Format file name. =DIR-PATH=, diff --git a/denote.el b/denote.el index 61cbf3478f..d6f569a15a 100644 --- a/denote.el +++ b/denote.el @@ -2513,23 +2513,19 @@ If more than one file type correspond to this file extension, use the first file type for which the :title-key-regexp in `denote-file-types' matches in the file. -If no file type in `denote-file-types' has the file extension, -the file type is assumed to be the first one in `denote-file-types'." +Return nil if the file type is not recognized." (cond ((denote--file-type-org-extra-p) 'org) (file - (let* ((extension (denote-get-file-extension-sans-encryption file)) - (types (denote--file-types-with-extension extension))) - (cond ((null types) - (caar denote-file-types)) - ((= (length types) 1) - (caar types)) - (t - (or (car (seq-find - (lambda (type) - (denote--regexp-in-file-p (plist-get (cdr type) :title-key-regexp) file)) - types)) - (caar types)))))))) + (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))))))) (defun denote--file-attributes-time (file) "Return `file-attribute-modification-time' of FILE as identifier." diff --git a/tests/denote-test.el b/tests/denote-test.el index a2daa9a6a2..cbdeadfb05 100644 --- a/tests/denote-test.el +++ b/tests/denote-test.el @@ -375,11 +375,10 @@ Extend what we do in `denote-test--denote-file-type-extensions'." (ert-deftest denote-test--denote-filetype-heuristics () "Test that `denote-filetype-heuristics' gets the correct file type." - (should (and (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing") (caar denote-file-types)) + (should (and (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing") nil) (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing.org") 'org) (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing.org.gpg") 'org) (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing.org.age") 'org) - (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing") 'org) (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing.txt") 'text) (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing.txt.gpg") 'text) (eq (denote-filetype-heuristics "20231010T105034--some-test-file__denote_testing.txt.age") 'text)