emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Vasilij Schneidermann <mail@vasilij.de>
To: Bastien <bzg@gnu.org>
Cc: emacs-orgmode@gnu.org
Subject: 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/)]
Date: Tue, 8 Sep 2020 22:18:45 +0200	[thread overview]
Message-ID: <20200908201845.GA1346@odonien.localdomain> (raw)
In-Reply-To: <87v9gsff0g.fsf@gnu.org>


[-- 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 --]

  reply	other threads:[~2020-09-08 20:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03  8:50 Bug: [PATCH] org-datetree-insert-line doesn't honor headline spacing customization [9.3 (release_9.3 @ /usr/share/emacs/27.1/lisp/org/)] Vasilij Schneidermann
2020-09-05 14:57 ` Bastien
2020-09-08 20:18   ` Vasilij Schneidermann [this message]
2020-09-09  8:08     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200908201845.GA1346@odonien.localdomain \
    --to=mail@vasilij.de \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).