Browse Source

Fix `org-auto-repeat-maybe'

* lisp/org.el (org-auto-repeat-maybe): Fix `org-auto-repeat-maybe'.

* testing/lisp/test-org.el (test-org/auto-repeat-maybe): Add test.

Reported-by: Samuel Wales <samologist@gmail.com>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-09/msg00298.html>
Nicolas Goaziou 1 year ago
parent
commit
25f12218d2
2 changed files with 17 additions and 3 deletions
  1. 3 2
      lisp/org.el
  2. 14 1
      testing/lisp/test-org.el

+ 3 - 2
lisp/org.el

@@ -13053,8 +13053,9 @@ This function is run automatically after each state change to a DONE state."
 	  ;; a clock, set LAST_REPEAT property.
 	  (when (or org-log-repeat
 		    (catch :clock
-		      (while (re-search-forward org-clock-line-re end t)
-			(when (org-at-clock-log-p) (throw :clock t)))))
+		      (save-excursion
+			(while (re-search-forward org-clock-line-re end t)
+			  (when (org-at-clock-log-p) (throw :clock t))))))
 	    (org-entry-put nil "LAST_REPEAT" (format-time-string
 					      (org-time-stamp-format t t)
 					      (current-time))))

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

@@ -6047,7 +6047,7 @@ Paragraph<point>"
       (cl-letf (((symbol-function 'org-add-log-setup)
 		 (lambda (&rest args) nil)))
 	(org-test-with-temp-text
-	    "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
+	    "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
 	  (org-todo "DONE")
 	  (buffer-string))))))
   ;; When a SCHEDULED entry has no repeater, remove it upon repeating
@@ -6059,6 +6059,19 @@ Paragraph<point>"
       (org-test-with-temp-text
 	  "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
 	(org-todo "DONE")
+	(buffer-string)))))
+  ;; Properly advance repeater even when a clock entry is specified
+  ;; and `org-log-repeat' is nil.
+  (should
+   (string-match-p
+    "SCHEDULED: <2014-03-29"
+    (let ((org-log-repeat nil)
+	  (org-todo-keywords '((sequence "TODO" "DONE"))))
+      (org-test-with-temp-text
+	  "* TODO H
+SCHEDULED: <2012-03-29 Thu +2y>
+CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] =>  6:40"
+	(org-todo "DONE")
 	(buffer-string))))))