On 2024-05-17 05:22, Ihor Radchenko wrote:
Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=288c7069c

Thanks Kris for reporting, and thanks Rens for hunting down the cause!
Thanks for the prompt fix, Ihor! I tested it out and confirmed I'm not seeing a blank space after the LOGBOOK anymore.

However, I did notice that it now errors out when creating the LOGBOOK on a heading which is at the end of the buffer. The error is:

Error in post-command-hook (org-add-log-note): (end-of-buffer)

I did some debugging and found that the error was coming from the (forward-char) call in the following line:

(if (eolp) (forward-char) (insert "\n"))

I've taken a crack at fixing this, which seems to work correctly from all my tests. See attached for the patch file.

The basic reasoning behind the included changes is:
- Keep point at the end of the LOGBOOK entry (right after :END:) instead of needing it to be on the line after. - Adjust the values for folding the drawer and moving the point after folding based on the logic above.
From 2c53fa24e2a7abfa73e070145365d89ad1197b8a Mon Sep 17 00:00:00 2001
From: Kris Nelson <k...@kristofernelson.com>
Date: Sat, 18 May 2024 12:16:06 -0600
Subject: [PATCH] org-log-beginning: Fix error creating LOGBOOK drawer at end
 of buffer

* lisp/org.el (org-log-beginning): Fix regression after 288c7069c where
"Error in post-command-hook (org-add-log-note): (end-of-buffer)"
is displayed after creating the LOGBOOK drawer on a heading which is
at the end of the buffer.

Reported-by: Kris Nelson <k...@kristofernelson.com>
Link: https://orgmode.org/list/766237934.317726.1715720181...@office.mailbox.org
---
 lisp/org.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 4342ddd73..5e9f479fb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10676,10 +10676,10 @@ narrowing."
 	       (unless (bolp) (insert-and-inherit "\n"))
 	       (let ((beg (point)))
 	         (insert-and-inherit ":" drawer ":\n:END:")
-                 (if (eolp) (forward-char) (insert "\n"))
+                 (unless (eolp) (insert-and-inherit "\n") (backward-char))
 	         (org-indent-region beg (point))
-	         (org-fold-region (line-end-position -1) (1- (point)) t 'drawer))))
-	   (end-of-line -1))))
+	         (org-fold-region (line-end-position 0) (point) t 'drawer))))
+	   (end-of-line 0))))
       (t
        (org-end-of-meta-data org-log-state-notes-insert-after-drawers)
        (let ((endpos (point)))
-- 
2.45.1

Reply via email to