"Jorge P. de Morais Neto" <jorge+l...@disroot.org> writes:

> - Expected behavior: Org should clock in the first heading, then clock
>   out from it, prompt for a note, and clock in the second heading (in
>   batch mode, Emacs should print some clocking messages and then exit
>   successfully).
> - What happens: Org errors out:
>   user-error: Before first headline at position 164 in buffer *Org Note*

Confirmed

The fix is attached.

Best,
Ihor

>From 7dc855ae1d7992eaacc2cab13a39c6000e4e66bf Mon Sep 17 00:00:00 2001
Message-Id: <7dc855ae1d7992eaacc2cab13a39c6000e4e66bf.1622468529.git.yanta...@gmail.com>
From: Ihor Radchenko <yanta...@gmail.com>
Date: Mon, 31 May 2021 21:39:51 +0800
Subject: [PATCH] Correctly handle org-log-note-clock-out non-interactively

* lisp/org-clock.el (org-clock-out): Delay log popup to
after-command-hook to avoid messing up non-interactive calls.
`org-add-log-setup' without 'note argument would raise interactive
note buffer immediately, so we do pass the 'note argument.
---
 lisp/org-clock.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 3b7d97639..0328bddd3 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1691,7 +1691,7 @@ (defun org-clock-out (&optional switch-to-state fail-quietly at-time)
 				(line-beginning-position 2)))
 		(org-log-note-clock-out
 		 (org-add-log-setup
-		  'clock-out nil nil nil
+		  'clock-out nil nil 'note
 		  (concat "# Task: " (org-get-heading t) "\n\n"))))
 	  (when org-clock-mode-line-timer
 	    (cancel-timer org-clock-mode-line-timer)
-- 
2.26.3

Reply via email to