mirror of
https://github.com/protesilaos/denote.git
synced 2026-09-10 07:16:20 -04:00
commit
5d4b9f9089
18
denote.el
18
denote.el
|
|
@ -1196,11 +1196,12 @@ For our purposes, a note must satisfy `file-regular-p' and
|
|||
This tests the rules of Denote's file-naming scheme. Sluggification is
|
||||
ignored. It is done by removing all file name components and validating
|
||||
what remains."
|
||||
(let ((filename (file-name-nondirectory file))
|
||||
(title (denote-retrieve-filename-title file))
|
||||
(keywords-string (denote-retrieve-filename-keywords file))
|
||||
(signature (denote-retrieve-filename-signature file))
|
||||
(identifier (denote-retrieve-filename-identifier file)))
|
||||
(let* ((initial-filename (file-name-nondirectory file))
|
||||
(filename initial-filename)
|
||||
(title (denote-retrieve-filename-title file))
|
||||
(keywords-string (denote-retrieve-filename-keywords file))
|
||||
(signature (denote-retrieve-filename-signature file))
|
||||
(identifier (denote-retrieve-filename-identifier file)))
|
||||
(when title
|
||||
(setq filename (replace-regexp-in-string (concat "\\(--" (regexp-quote title) "\\).*\\'") "" filename nil nil 1)))
|
||||
(when keywords-string
|
||||
|
|
@ -1212,8 +1213,9 @@ what remains."
|
|||
(setq filename (replace-regexp-in-string (concat "\\(@@" (regexp-quote identifier) "\\).*\\'") "" filename nil nil 1))
|
||||
(setq filename (replace-regexp-in-string (concat "\\(" (regexp-quote identifier) "\\).*\\'") "" filename nil nil 1))))
|
||||
;; What remains should be the empty string or the file extension.
|
||||
(or (string-empty-p filename)
|
||||
(string-prefix-p "." filename))))
|
||||
(and (not (string-prefix-p "." initial-filename))
|
||||
(or (string-empty-p filename)
|
||||
(string-prefix-p "." filename)))))
|
||||
|
||||
(defun denote-file-has-signature-p (file)
|
||||
"Return non-nil if FILE has a Denote identifier."
|
||||
|
|
@ -2227,6 +2229,8 @@ which case it is not added to the base file name."
|
|||
(setq file-name (concat file-name "__" (denote-keywords-combine (denote-sluggify-keywords keywords)))))
|
||||
((and (eq component 'signature) signature (not (string-empty-p signature)))
|
||||
(setq file-name (concat file-name "==" (denote-sluggify 'signature signature))))))
|
||||
(when (string-empty-p file-name)
|
||||
(error "There should be at least one file name component"))
|
||||
(setq file-name (concat file-name extension))
|
||||
;; Do not prepend identifier with @@ if it is the first component and has the format 00000000T000000.
|
||||
(when (and (string-prefix-p "@@" file-name)
|
||||
|
|
|
|||
|
|
@ -179,13 +179,15 @@ Extend what we do in `denote-test--denote-file-type-extensions'."
|
|||
"Test that `denote--format-front-matter' formats front matter correctly.
|
||||
To make the test reproducible, set `denote-date-format' to a value that
|
||||
does not involve the time zone."
|
||||
(let ((denote-date-format "%Y-%m-%d"))
|
||||
(let ((denote-date-format "%Y-%m-%d")
|
||||
(denote-front-matter-components-present-even-if-empty-value '(title keywords signature date identifier)))
|
||||
(should (and (equal (denote--format-front-matter "" (date-to-time "20240101T120000") '("") "" "" 'text)
|
||||
(mapconcat #'identity
|
||||
'("title: "
|
||||
"date: 2024-01-01"
|
||||
"tags: "
|
||||
"identifier: "
|
||||
"signature: "
|
||||
"---------------------------\n\n")
|
||||
"\n"))
|
||||
|
||||
|
|
@ -198,6 +200,7 @@ does not involve the time zone."
|
|||
"date: 2023-06-05"
|
||||
"tags: one two"
|
||||
"identifier: 20230605T102234"
|
||||
"signature: sig"
|
||||
"---------------------------\n\n")
|
||||
"\n"))))
|
||||
|
||||
|
|
@ -207,6 +210,7 @@ does not involve the time zone."
|
|||
"#+date: 2024-01-01"
|
||||
"#+filetags: "
|
||||
"#+identifier: "
|
||||
"#+signature: "
|
||||
"\n")
|
||||
"\n"))
|
||||
|
||||
|
|
@ -219,6 +223,7 @@ does not involve the time zone."
|
|||
"#+date: 2023-06-05"
|
||||
"#+filetags: :one:two:"
|
||||
"#+identifier: 20230605T102234"
|
||||
"#+signature: sig"
|
||||
"\n")
|
||||
"\n"))))
|
||||
|
||||
|
|
@ -229,6 +234,7 @@ does not involve the time zone."
|
|||
"date: 2024-01-01"
|
||||
"tags: []"
|
||||
"identifier: \"\""
|
||||
"signature: \"\""
|
||||
"---"
|
||||
"\n")
|
||||
"\n"))
|
||||
|
|
@ -243,6 +249,7 @@ does not involve the time zone."
|
|||
"date: 2023-06-05"
|
||||
"tags: [\"one\", \"two\"]"
|
||||
"identifier: \"20230605T102234\""
|
||||
"signature: \"sig\""
|
||||
"---"
|
||||
"\n")
|
||||
"\n"))))
|
||||
|
|
@ -254,6 +261,7 @@ does not involve the time zone."
|
|||
"date = 2024-01-01"
|
||||
"tags = []"
|
||||
"identifier = \"\""
|
||||
"signature = \"\""
|
||||
"+++"
|
||||
"\n")
|
||||
"\n"))
|
||||
|
|
@ -268,6 +276,7 @@ does not involve the time zone."
|
|||
"date = 2023-06-05"
|
||||
"tags = [\"one\", \"two\"]"
|
||||
"identifier = \"20230605T102234\""
|
||||
"signature = \"sig\""
|
||||
"+++"
|
||||
"\n")
|
||||
"\n"))))))
|
||||
|
|
@ -302,29 +311,40 @@ does not involve the time zone."
|
|||
(denote--file-extension 'org)
|
||||
""))
|
||||
|
||||
(should-error (denote-format-file-name
|
||||
(denote-directory)
|
||||
nil
|
||||
kws
|
||||
title
|
||||
(denote--file-extension 'org)
|
||||
""))
|
||||
|
||||
(should-error (denote-format-file-name
|
||||
(denote-directory)
|
||||
""
|
||||
kws
|
||||
title
|
||||
nil
|
||||
""
|
||||
(denote--file-extension 'org)
|
||||
""))
|
||||
|
||||
(should-error (denote-format-file-name
|
||||
(denote-directory)
|
||||
"0123456"
|
||||
kws
|
||||
title
|
||||
(denote--file-extension 'org)
|
||||
""))
|
||||
(should (equal (denote-format-file-name
|
||||
(denote-directory)
|
||||
nil
|
||||
kws
|
||||
title
|
||||
(denote--file-extension 'org)
|
||||
"")
|
||||
"/tmp/test-denote/--some-test__one_two.org"))
|
||||
|
||||
(should (equal (denote-format-file-name
|
||||
(denote-directory)
|
||||
""
|
||||
kws
|
||||
title
|
||||
(denote--file-extension 'org)
|
||||
"")
|
||||
"/tmp/test-denote/--some-test__one_two.org"))
|
||||
|
||||
(should (equal (denote-format-file-name
|
||||
(denote-directory)
|
||||
"0123456"
|
||||
kws
|
||||
title
|
||||
(denote--file-extension 'org)
|
||||
"")
|
||||
"/tmp/test-denote/@@0123456--some-test__one_two.org"))
|
||||
|
||||
(should (equal (denote-format-file-name
|
||||
(denote-directory)
|
||||
|
|
|
|||
Loading…
Reference in a new issue