[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 6446650c36 3/9: Make date parameter a date objec
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 6446650c36 3/9: Make date parameter a date object in denote--format-front-matter |
Date: |
Sun, 3 Nov 2024 03:57:44 -0500 (EST) |
branch: externals/denote
commit 6446650c36d5496912c1a1132080d5b3b63f4bc0
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Make date parameter a date object in denote--format-front-matter
---
denote.el | 23 +++----
tests/denote-test.el | 183 ++++++++++++++++++++++++++-------------------------
2 files changed, 101 insertions(+), 105 deletions(-)
diff --git a/denote.el b/denote.el
index ea44118bcc..00412d940a 100644
--- a/denote.el
+++ b/denote.el
@@ -1796,13 +1796,13 @@ this list for new note creation. The default is
`org'.")
(defun denote--format-front-matter (title date keywords id filetype)
"Front matter for new notes.
-TITLE, DATE, and ID are all strings or functions that return a
-string. KEYWORDS is a list of strings. FILETYPE is one of the
-values of variable `denote-file-type'."
+TITLE and ID are strings. DATE is a date object. KEYWORDS is a list of
+strings. FILETYPE is one of the values of variable `denote-file-type'."
(let* ((fm (denote--front-matter filetype))
(title (denote--format-front-matter-title title filetype))
+ (date-string (denote--date date filetype))
(kws (denote--format-front-matter-keywords keywords filetype)))
- (if fm (format fm title date kws id) "")))
+ (if fm (format fm title date-string kws id) "")))
;;;; Front matter or content retrieval functions
@@ -2130,10 +2130,7 @@ TEMPLATE, and SIGNATURE should be valid for note
creation."
(let* ((path (denote-format-file-name
directory id keywords title (denote--file-extension file-type)
signature))
(buffer (find-file path))
- (header (denote--format-front-matter
- title (denote--date date file-type) keywords
- id
- file-type)))
+ (header (denote--format-front-matter title date keywords id
file-type)))
(when (file-regular-p path)
(user-error "A file named `%s' already exists" path))
(with-current-buffer buffer
@@ -2943,8 +2940,7 @@ If a buffer is visiting the file, its name is updated."
The TITLE, KEYWORDS ID, and FILE-TYPE are passed from the
renaming command and are used to construct a new front matter
block if appropriate."
- (when-let* ((date (denote--date (date-to-time id) file-type))
- (new-front-matter (denote--format-front-matter title date
keywords id file-type)))
+ (when-let* ((new-front-matter (denote--format-front-matter title
(date-to-time id) keywords id file-type)))
(with-current-buffer (find-file-noselect file)
(goto-char (point-min))
(insert new-front-matter))))
@@ -2977,7 +2973,7 @@ With optional SAVE-BUFFER, save the buffer corresponding
to FILE.
This function is for use in the commands `denote-keywords-add',
`denote-keywords-remove', `denote-dired-rename-files', or
related."
- (let* ((new-front-matter (denote--format-front-matter "" "" keywords ""
file-type))
+ (let* ((new-front-matter (denote--format-front-matter "" (current-time)
keywords "" file-type))
(new-keywords-line
(denote--retrieve-front-matter-keywords-line-from-content new-front-matter
file-type)))
(with-current-buffer (find-file-noselect file)
(save-excursion
@@ -3001,7 +2997,7 @@ prompt to confirm the rewriting of the front matter.
Otherwise
produce a `y-or-n-p' prompt to that effect."
(when-let* ((old-title-line (denote-retrieve-front-matter-title-line file
file-type))
(old-keywords-line (denote-retrieve-front-matter-keywords-line
file file-type))
- (new-front-matter (denote--format-front-matter title "" keywords
"" file-type))
+ (new-front-matter (denote--format-front-matter title
(current-time) keywords "" file-type))
(new-title-line
(denote--retrieve-front-matter-title-line-from-content new-front-matter
file-type))
(new-keywords-line
(denote--retrieve-front-matter-keywords-line-from-content new-front-matter
file-type)))
(with-current-buffer (find-file-noselect file)
@@ -5121,8 +5117,7 @@ Consult the manual for template samples."
(`(,title ,keywords _ ,directory ,date ,template ,signature)
(denote--creation-prepare-note-data title keywords 'org
directory date template signature))
(id (denote--find-first-unused-id (denote-get-identifier date)))
- (front-matter (denote--format-front-matter
- title (denote--date date 'org) keywords id 'org))
+ (front-matter (denote--format-front-matter title date keywords
id 'org))
(template-string (cond ((stringp template) template)
((functionp template) (funcall template))
(t (user-error "Invalid template")))))
diff --git a/tests/denote-test.el b/tests/denote-test.el
index 7f19fe2206..e3e05689ff 100644
--- a/tests/denote-test.el
+++ b/tests/denote-test.el
@@ -177,97 +177,98 @@ Extend what we do in
`denote-test--denote-file-type-extensions'."
(ert-deftest denote-test--denote--format-front-matter ()
"Test that `denote--format-front-matter' formats front matter correctly."
- (should (and (equal (denote--format-front-matter "" "" '("") "" 'text)
- (mapconcat #'identity
- '("title: "
- "date: "
- "tags: "
- "identifier: "
- "---------------------------\n\n")
- "\n"))
-
- (equal
- (denote--format-front-matter
- "Some test" "2023-06-05" '("one" "two")
- "20230605T102234" 'text)
- (mapconcat #'identity
- '("title: Some test"
- "date: 2023-06-05"
- "tags: one two"
- "identifier: 20230605T102234"
- "---------------------------\n\n")
- "\n"))))
-
- (should (and (equal (denote--format-front-matter "" "" nil "" 'org)
- (mapconcat #'identity
- '("#+title: "
- "#+date: "
- "#+filetags: "
- "#+identifier: "
- "\n")
- "\n"))
-
- (equal
- (denote--format-front-matter
- "Some test" "2023-06-05" '("one" "two")
- "20230605T102234" 'org)
- (mapconcat #'identity
- '("#+title: Some test"
- "#+date: 2023-06-05"
- "#+filetags: :one:two:"
- "#+identifier: 20230605T102234"
- "\n")
- "\n"))))
-
- (should (and (equal (denote--format-front-matter "" "" nil "" 'markdown-yaml)
- (mapconcat #'identity
- '("---"
- "title: \"\""
- "date: "
- "tags: []"
- "identifier: \"\""
- "---"
- "\n")
- "\n"))
-
- (equal
- (denote--format-front-matter
- "Some test" "2023-06-05" '("one" "two")
- "20230605T102234" 'markdown-yaml)
- (mapconcat #'identity
- '("---"
- "title: \"Some test\""
- "date: 2023-06-05"
- "tags: [\"one\", \"two\"]"
- "identifier: \"20230605T102234\""
- "---"
- "\n")
- "\n"))))
-
-(should (and (equal (denote--format-front-matter "" "" nil "" 'markdown-toml)
- (mapconcat #'identity
- '("+++"
- "title = \"\""
- "date = "
- "tags = []"
- "identifier = \"\""
- "+++"
- "\n")
- "\n"))
-
- (equal
- (denote--format-front-matter
- "Some test" "2023-06-05" '("one" "two")
- "20230605T102234" 'markdown-toml)
- (mapconcat #'identity
- '("+++"
- "title = \"Some test\""
- "date = 2023-06-05"
- "tags = [\"one\", \"two\"]"
- "identifier = \"20230605T102234\""
- "+++"
- "\n")
- "\n")))))
+ (let ((denote-date-format "%Y-%m-%d"))
+ (should (and (equal (denote--format-front-matter "" (date-to-time
"20240101T120000") '("") "" 'text)
+ (mapconcat #'identity
+ '("title: "
+ "date: 2024-01-01"
+ "tags: "
+ "identifier: "
+ "---------------------------\n\n")
+ "\n"))
+
+ (equal
+ (denote--format-front-matter
+ "Some test" (date-to-time "2023-06-05") '("one" "two")
+ "20230605T102234" 'text)
+ (mapconcat #'identity
+ '("title: Some test"
+ "date: 2023-06-05"
+ "tags: one two"
+ "identifier: 20230605T102234"
+ "---------------------------\n\n")
+ "\n"))))
+
+ (should (and (equal (denote--format-front-matter "" (date-to-time
"20240101T120000") nil "" 'org)
+ (mapconcat #'identity
+ '("#+title: "
+ "#+date: 2024-01-01"
+ "#+filetags: "
+ "#+identifier: "
+ "\n")
+ "\n"))
+
+ (equal
+ (denote--format-front-matter
+ "Some test" (date-to-time "2023-06-05") '("one" "two")
+ "20230605T102234" 'org)
+ (mapconcat #'identity
+ '("#+title: Some test"
+ "#+date: 2023-06-05"
+ "#+filetags: :one:two:"
+ "#+identifier: 20230605T102234"
+ "\n")
+ "\n"))))
+
+ (should (and (equal (denote--format-front-matter "" (date-to-time
"20240101T120000") nil "" 'markdown-yaml)
+ (mapconcat #'identity
+ '("---"
+ "title: \"\""
+ "date: 2024-01-01"
+ "tags: []"
+ "identifier: \"\""
+ "---"
+ "\n")
+ "\n"))
+
+ (equal
+ (denote--format-front-matter
+ "Some test" (date-to-time "2023-06-05") '("one" "two")
+ "20230605T102234" 'markdown-yaml)
+ (mapconcat #'identity
+ '("---"
+ "title: \"Some test\""
+ "date: 2023-06-05"
+ "tags: [\"one\", \"two\"]"
+ "identifier: \"20230605T102234\""
+ "---"
+ "\n")
+ "\n"))))
+
+ (should (and (equal (denote--format-front-matter "" (date-to-time
"20240101T120000") nil "" 'markdown-toml)
+ (mapconcat #'identity
+ '("+++"
+ "title = \"\""
+ "date = 2024-01-01"
+ "tags = []"
+ "identifier = \"\""
+ "+++"
+ "\n")
+ "\n"))
+
+ (equal
+ (denote--format-front-matter
+ "Some test" (date-to-time "2023-06-05") '("one" "two")
+ "20230605T102234" 'markdown-toml)
+ (mapconcat #'identity
+ '("+++"
+ "title = \"Some test\""
+ "date = 2023-06-05"
+ "tags = [\"one\", \"two\"]"
+ "identifier = \"20230605T102234\""
+ "+++"
+ "\n")
+ "\n"))))))
(ert-deftest denote-test--denote-format-file-name ()
"Test that `denote-format-file-name' returns all expected paths."
- [elpa] externals/denote updated (f3ac69fcd3 -> 0ea4d88a59), ELPA Syncer, 2024/11/03
- [elpa] externals/denote af2e6a33a3 1/9: Add denote--retrieve-front-matter-*-from-content functions, ELPA Syncer, 2024/11/03
- [elpa] externals/denote 6446650c36 3/9: Make date parameter a date object in denote--format-front-matter,
ELPA Syncer <=
- [elpa] externals/denote bd50fbba94 5/9: Remove denote--front-matter-{title/keywords} functions, ELPA Syncer, 2024/11/03
- [elpa] externals/denote 0ea4d88a59 9/9: Merge pull request #472 from jeanphilippegg/front-matter-functions, ELPA Syncer, 2024/11/03
- [elpa] externals/denote f0908dbcc1 2/9: Remove denote--get-{title/keywords}-line-from-front-matter functions, ELPA Syncer, 2024/11/03
- [elpa] externals/denote 4cd24c9730 4/9: Format identifier in denote--format-front-matter, ELPA Syncer, 2024/11/03
- [elpa] externals/denote 7ccddb5837 6/9: Add signature parameter to denote--format-front-matter, ELPA Syncer, 2024/11/03
- [elpa] externals/denote 4fdae80128 8/9: Refactor denote-rename-file-using-front-matter, ELPA Syncer, 2024/11/03
- [elpa] externals/denote 512672e173 7/9: Add signature parameter to denote--add-front-matter, ELPA Syncer, 2024/11/03