浏览代码

Fix duplicate logbook entry for repeated tasks

* lisp/org.el (org-add-log-setup): Always run `org-add-log-note' via
`post-command-hook'.  Otherwise, there is no way to know if a note was
requested for `this-command'.  Running `org-add-log-note' directly
would, for example, break `org-auto-repeat-maybe' as reported in [1].

* lisp/org-agenda.el (org-agenda-todo): Avoid reintroducing the bug
fixed in c670379adf.

* testing/lisp/test-org.el: Add test checking the reported bug.

[1] https://orgmode.org/list/CAOn=hbcaW1R6vtun-E2r4LS=j3dp=VjqmjGtzy8UC1SyPArKbA@mail.gmail.com
Ihor Radchenko 3 年之前
父节点
当前提交
a3c912cb29
共有 3 个文件被更改,包括 28 次插入5 次删除
  1. 5 1
      lisp/org-agenda.el
  2. 1 3
      lisp/org.el
  3. 22 1
      testing/lisp/test-org.el

+ 5 - 1
lisp/org-agenda.el

@@ -9436,7 +9436,11 @@ the same tree node, and the headline of the tree node in the Org file."
 	 (goto-char pos)
 	 (goto-char pos)
 	 (org-show-context 'agenda)
 	 (org-show-context 'agenda)
 	 (let ((current-prefix-arg arg))
 	 (let ((current-prefix-arg arg))
-	   (call-interactively 'org-todo))
+	   (call-interactively 'org-todo)
+           ;; Make sure that log is recorded in current undo.
+           (when (and org-log-setup
+                      (not (eq org-log-note-how 'note)))
+             (org-add-log-note)))
 	 (and (bolp) (forward-char 1))
 	 (and (bolp) (forward-char 1))
 	 (setq newhead (org-get-heading))
 	 (setq newhead (org-get-heading))
 	 (when (and org-agenda-headline-snapshot-before-repeat
 	 (when (and org-agenda-headline-snapshot-before-repeat

+ 1 - 3
lisp/org.el

@@ -10945,9 +10945,7 @@ EXTRA is additional text that will be inserted into the notes buffer."
 	org-log-note-extra extra
 	org-log-note-extra extra
 	org-log-note-effective-time (org-current-effective-time)
 	org-log-note-effective-time (org-current-effective-time)
         org-log-setup t)
         org-log-setup t)
-  (if (eq how 'note)
-      (add-hook 'post-command-hook 'org-add-log-note 'append)
-    (org-add-log-note purpose)))
+  (add-hook 'post-command-hook 'org-add-log-note 'append))
 
 
 (defun org-skip-over-state-notes ()
 (defun org-skip-over-state-notes ()
   "Skip past the list of State notes in an entry."
   "Skip past the list of State notes in an entry."

+ 22 - 1
testing/lisp/test-org.el

@@ -7411,7 +7411,28 @@ Paragraph<point>"
 SCHEDULED: <2012-03-29 Thu +2y>
 SCHEDULED: <2012-03-29 Thu +2y>
 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] =>  6:40"
 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] =>  6:40"
 	(org-todo "DONE")
 	(org-todo "DONE")
-	(buffer-string))))))
+	(buffer-string)))))
+  ;; Make sure that logbook state change record does not get
+  ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
+  (should
+   (string-match-p
+    (rx "* TODO Read book
+SCHEDULED: <2021-06-16 Wed +1d>
+:PROPERTIES:
+:LAST_REPEAT:" (1+ nonl) "
+:END:
+- State \"DONE\"       from \"TODO\"" (1+ nonl) buffer-end)
+    (let ((org-log-repeat 'time)
+	  (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
+          (org-log-into-drawer nil))
+      (org-test-with-temp-text
+          "* TODO Read book
+SCHEDULED: <2021-06-15 Tue +1d>"
+        (org-todo "DONE")
+        (when (memq 'org-add-log-note post-command-hook)
+          (org-add-log-note))
+        (buffer-string))))))
+
 
 
 
 
 ;;; Timestamps API
 ;;; Timestamps API