* Re: Bug: [PATCH] org-datetree-insert-line doesn't honor headline spacing customization [9.3 (release_9.3 @ /usr/share/emacs/27.1/lisp/org/)]
2020-09-05 14:57 ` Bastien
@ 2020-09-08 20:18 ` Vasilij Schneidermann
2020-09-09 8:08 ` Bastien
0 siblings, 1 reply; 4+ messages in thread
From: Vasilij Schneidermann @ 2020-09-08 20:18 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 428 bytes --]
Hello Bastien,
> Thanks for the patch. I tried it and these two tests fail:
>
> FAILED test-org-datetree/find-date-create
> FAILED test-org-datetree/find-iso-week-create
>
> Perhaps you can check the value of `org-blank-before-new-entry' and
> insert a blank line only if needed?
I've looked at the tests and concluded that your proposed approach is better
and updated the patch accordingly.
Vasilij
[-- Attachment #1.2: 0001-Ensure-blank-line-if-needed-for-datetrees.patch --]
[-- Type: text/plain, Size: 10292 bytes --]
From 47085037a1882a2a723076a47972feb35cc42a7b Mon Sep 17 00:00:00 2001
From: Vasilij Schneidermann <mail@vasilij.de>
Date: Tue, 8 Sep 2020 22:15:25 +0200
Subject: [PATCH] Ensure blank line if needed for datetrees
---
lisp/org-datetree.el | 2 ++
testing/lisp/test-org-datetree.el | 56 +++++++++++++++----------------
2 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el
index ce91591f1..d4ccc84bb 100644
--- a/lisp/org-datetree.el
+++ b/lisp/org-datetree.el
@@ -185,6 +185,8 @@ inserted into the buffer."
(defun org-datetree-insert-line (year &optional month day text)
(delete-region (save-excursion (skip-chars-backward " \t\n") (point)) (point))
+ (when (assq 'heading org-blank-before-new-entry)
+ (insert "\n"))
(insert "\n" (make-string org-datetree-base-level ?*) " \n")
(backward-char)
(when month (org-do-demote))
diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el
index 5557d5e23..daebcaace 100644
--- a/testing/lisp/test-org-datetree.el
+++ b/testing/lisp/test-org-datetree.el
@@ -26,7 +26,7 @@
;; When date is missing, create it.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* 2012-03-29 .*\\'"
(org-test-with-temp-text ""
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
@@ -34,7 +34,7 @@
;; Do not create new year node when one exists.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* 2012-03-29 .*\\'"
(org-test-with-temp-text "* 2012\n"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
@@ -42,24 +42,24 @@
;; Do not create new month node when one exists.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
- (org-test-with-temp-text "* 2012\n** 2012-03 month"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* 2012-03-29 .*\\'"
+ (org-test-with-temp-text "* 2012\n\n** 2012-03 month"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
(org-trim (buffer-string)))))
;; Do not create new day node when one exists.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
- (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* 2012-03-29 .*\\'"
+ (org-test-with-temp-text "* 2012\n\n** 2012-03 month\n\n*** 2012-03-29 day"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
(org-trim (buffer-string)))))
;; Sort new entry in right place.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-02 .*\n\\*\\*\\* 2012-02-01 .*\n\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
- (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
+ "\\`\\* 2012\n\n\\*\\* 2012-02 .*\n\n\\*\\*\\* 2012-02-01 .*\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* 2012-03-29 .*\\'"
+ (org-test-with-temp-text "* 2012\n\n** 2012-03 month\n\n*** 2012-03-29 day"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012))
(org-datetree-find-date-create '(2 1 2012)))
@@ -68,14 +68,14 @@
;; in entry. When set to `inactive', insert an inactive one.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* \\(2012-03-29\\) .*\n[ \t]*<\\1.*?>\\'"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* \\(2012-03-29\\) .*\n[ \t]*<\\1.*?>\\'"
(org-test-with-temp-text "* 2012\n"
(let ((org-datetree-add-timestamp t))
(org-datetree-find-date-create '(3 29 2012)))
(org-trim (buffer-string)))))
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* \\(2012-03-29\\) .*\n[ \t]*\\[\\1.*?\\]\\'"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\n\n\\*\\*\\* \\(2012-03-29\\) .*\n[ \t]*\\[\\1.*?\\]\\'"
(org-test-with-temp-text "* 2012\n"
(let ((org-datetree-add-timestamp 'inactive))
(org-datetree-find-date-create '(3 29 2012)))
@@ -91,9 +91,9 @@
(org-trim (buffer-string)))))
(should
(string-match
- "\\*\\* H1.1\n:PROPERTIES:\n:DATE_TREE: t\n:END:\n\\*\\*\\* 2012"
+ "\\*\\* H1.1\n:PROPERTIES:\n:DATE_TREE: t\n:END:\n\n\\*\\*\\* 2012"
(org-test-with-temp-text
- "* H1\n** H1.1\n:PROPERTIES:\n:DATE_TREE: t\n:END:\n* H2"
+ "* H1\n\n** H1.1\n:PROPERTIES:\n:DATE_TREE: t\n:END:\n\n* H2"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
(org-trim (buffer-string)))))
@@ -101,14 +101,14 @@
(should
(string-match
"\\*\\*\\* 2012-03-29"
- (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
+ (org-test-with-temp-text "* 2012\n\n** 2012-03 month\n\n*** 2012-03-29 day"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
(buffer-substring (point) (line-end-position)))))
(should
(string-match
"\\*\\*\\* 2012-03-29"
- (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
+ (org-test-with-temp-text "* 2012\n\n** 2012-03 month\n\n*** 2012-03-29 day"
(let ((org-datetree-add-timestamp t))
(org-datetree-find-date-create '(3 29 2012)))
(buffer-substring (point) (line-end-position))))))
@@ -118,7 +118,7 @@
;; When date is missing, create it with the entry under month.
(should
(string-match
- "\\`\\* 2012\n\\*\\* 2012-03 .*\\'"
+ "\\`\\* 2012\n\n\\*\\* 2012-03 .*\\'"
(org-test-with-temp-text ""
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-month-create '(3 29 2012)))
@@ -129,7 +129,7 @@
;; When date is missing, create it.
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\\'"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* 2014-12-31 .*\\'"
(org-test-with-temp-text ""
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
@@ -137,7 +137,7 @@
;; Do not create new year node when one exists.
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\\'"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* 2014-12-31 .*\\'"
(org-test-with-temp-text "* 2015\n"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
@@ -145,23 +145,23 @@
;; Do not create new month node when one exists.
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\\'"
- (org-test-with-temp-text "* 2015\n** 2015-W01"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* 2014-12-31 .*\\'"
+ (org-test-with-temp-text "* 2015\n\n** 2015-W01"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
(org-trim (buffer-string)))))
;; Do not create new day node when one exists.
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\\'"
- (org-test-with-temp-text "* 2015\n** 2015-W01\n*** 2014-12-31 day"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* 2014-12-31 .*\\'"
+ (org-test-with-temp-text "* 2015\n\n** 2015-W01\n\n*** 2014-12-31 day"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
(org-trim (buffer-string)))))
;; Sort new entry in right place.
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\n\n\\*\\* 2015-W36\n\\*\\*\\* 2015-09-01 .*\\'"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* 2014-12-31 .*\n\n\\*\\* 2015-W36\n\n\\*\\*\\* 2015-09-01 .*\\'"
(org-test-with-temp-text "* 2015"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(9 1 2015))
@@ -171,14 +171,14 @@
;; in entry. When set to `inactive', insert an inactive one.
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* \\(2014-12-31\\) .*\n[ \t]*<\\1.*?>\\'"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* \\(2014-12-31\\) .*\n[ \t]*<\\1.*?>\\'"
(org-test-with-temp-text "* 2015\n"
(let ((org-datetree-add-timestamp t))
(org-datetree-find-iso-week-create '(12 31 2014)))
(org-trim (buffer-string)))))
(should
(string-match
- "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* \\(2014-12-31\\) .*\n[ \t]*\\[\\1.*?\\]\\'"
+ "\\`\\* 2015\n\n\\*\\* 2015-W01\n\n\\*\\*\\* \\(2014-12-31\\) .*\n[ \t]*\\[\\1.*?\\]\\'"
(org-test-with-temp-text "* 2015\n"
(let ((org-datetree-add-timestamp 'inactive))
(org-datetree-find-iso-week-create '(12 31 2014)))
@@ -194,9 +194,9 @@
(org-trim (buffer-string)))))
(should
(string-match
- "\\*\\* H1.1\n:PROPERTIES:\n:WEEK_TREE: t\n:END:\n\\*\\*\\* 2015"
+ "\\*\\* H1.1\n:PROPERTIES:\n:WEEK_TREE: t\n:END:\n\n\\*\\*\\* 2015"
(org-test-with-temp-text
- "* H1\n** H1.1\n:PROPERTIES:\n:WEEK_TREE: t\n:END:\n* H2"
+ "* H1\n** H1.1\n:PROPERTIES:\n:WEEK_TREE: t\n:END:\n\n* H2"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
(org-trim (buffer-string)))))
@@ -204,14 +204,14 @@
(should
(string-match
"\\*\\*\\* 2014-12-31"
- (org-test-with-temp-text "* 2015\n** 2015-W01\n*** 2014-12-31 day"
+ (org-test-with-temp-text "* 2015\n\n** 2015-W01\n\n*** 2014-12-31 day"
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
(buffer-substring (point) (line-end-position)))))
(should
(string-match
"\\*\\*\\* 2014-12-31"
- (org-test-with-temp-text "* 2015\n** 2015-W01\n*** 2014-12-31 day"
+ (org-test-with-temp-text "* 2015\n\n** 2015-W01\n\n*** 2014-12-31 day"
(let ((org-datetree-add-timestamp t))
(org-datetree-find-iso-week-create '(12 31 2014)))
(buffer-substring (point) (line-end-position))))))
--
2.28.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread