From 7c40a003166c9ab8f5f034b8bb6d506ed2b8b62f Mon Sep 17 00:00:00 2001 Message-Id: <7c40a003166c9ab8f5f034b8bb6d506ed2b8b62f.1655778085.git.yantar92@gmail.com> From: Ihor Radchenko Date: Tue, 21 Jun 2022 10:18:58 +0800 Subject: [PATCH] org-log-beginning: Fix for headline at eob with no trailing newline * lisp/org.el (org-log-beginning): Fix edge case when there is a headline at the end of buffer and that headline does not have a trailing newline. Fixes https://orgmode.org/list/m24k0ffjyd.fsf@ntnu.no --- lisp/org.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 220210992..78f51f9ad 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -10121,12 +10121,17 @@ (defun org-log-beginning (&optional create) (end-of-line -1)))) (t (org-end-of-meta-data org-log-state-notes-insert-after-drawers) - (skip-chars-forward " \t\n") - (beginning-of-line) - (unless org-log-states-order-reversed - (org-skip-over-state-notes) - (skip-chars-backward " \t\n") - (beginning-of-line 2))))) + (let ((endpos (point))) + (skip-chars-forward " \t\n") + (beginning-of-line) + (unless org-log-states-order-reversed + (org-skip-over-state-notes) + (skip-chars-backward " \t\n") + (beginning-of-line 2)) + ;; When current headline is at the end of buffer and does not + ;; end with trailing newline the above can move to the + ;; beginning of the headline. + (when (< (point) endpos)) (goto-char endpos))))) (if (bolp) (point) (line-beginning-position 2)))) (defun org-add-log-setup (&optional purpose state prev-state how extra) -- 2.35.1