Also obey to repeaters in inactive time stamps

* lisp/org.el (org-repeat-re): Accept inactive time stamps.
(org-auto-repeat-maybe): Small refactoring.  Find additional repeaters
also in inactive time stamps.
* testing/lisp/test-org.el (test-org/auto-repeat-maybe): Add test.

Reported-by: Leo Gaspard <orgmode@leo.gaspard.io>
<http://lists.gnu.org/r/emacs-orgmode/2018-11/msg00078.html>
This commit is contained in:
Nicolas Goaziou 2018-11-10 18:46:20 +01:00
parent 88ef9f26de
commit af81211fdc
2 changed files with 112 additions and 109 deletions

View File

@ -674,7 +674,8 @@ on a string that terminates immediately after the date.")
The time stamps may be either active or inactive.")
(defconst org-repeat-re
"<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
"[[<][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^]>\n]*?\
\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
"Regular expression for specifying repeated events.
After a match, group 1 contains the repeat expression.")
@ -12730,15 +12731,13 @@ This function is run automatically after each state change to a DONE state."
(org-log-done nil)
(org-todo-log-states nil)
(end (copy-marker (org-entry-end-position))))
(unwind-protect
(when (and repeat (not (zerop (string-to-number (substring repeat 1)))))
(when (and repeat (not (= 0 (string-to-number (substring repeat 1)))))
(when (eq org-log-repeat t) (setq org-log-repeat 'state))
(let ((to-state (or (org-entry-get nil "REPEAT_TO_STATE" 'selective)
(and (stringp org-todo-repeat-to-state)
org-todo-repeat-to-state)
(and org-todo-repeat-to-state org-last-state))))
(org-todo (cond
((and to-state (member to-state org-todo-keywords-1))
(org-todo (cond ((and to-state (member to-state org-todo-keywords-1))
to-state)
((eq interpret 'type) org-last-state)
(head)
@ -12769,7 +12768,7 @@ This function is run automatically after each state change to a DONE state."
org-log-repeat)))
(let ((planning-re (regexp-opt
(list org-scheduled-string org-deadline-string))))
(while (re-search-forward org-ts-regexp end t)
(while (re-search-forward org-ts-regexp-both end t)
(let* ((ts (match-string 0))
(planning? (org-at-planning-p))
(type (if (not planning?) "Plain:"
@ -12780,14 +12779,7 @@ This function is run automatically after each state change to a DONE state."
(cond
;; Ignore fake time-stamps (e.g., within comments).
((not (org-at-timestamp-p 'agenda)))
;; Time-stamps without a repeater are usually
;; skipped. However, a SCHEDULED time-stamp without
;; one is removed, as they are no longer relevant.
((not (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)"
ts))
(when (equal type org-scheduled-string)
(org-remove-timestamp-with-keyword type)))
(t
((string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" ts)
(let ((n (string-to-number (match-string 2 ts)))
(what (match-string 3 ts)))
(when (equal what "w") (setq n (* n 7) what "d"))
@ -12795,26 +12787,24 @@ This function is run automatically after each state change to a DONE state."
(not (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}"
ts)))
(user-error
"Cannot repeat in Repeat in %d hour(s) because no hour \
has been set"
"Cannot repeat in %d hour(s) because no hour has been set"
n))
;; Preparation, see if we need to modify the start
;; date for the change.
(when (match-end 1)
(let ((time (save-match-data
(org-time-string-to-time ts))))
(let ((time (save-match-data (org-time-string-to-time ts)))
(repeater-type (match-string 1 ts)))
(cond
((equal (match-string 1 ts) ".")
;; Shift starting date to today
(org-timestamp-change
(- (org-today) (time-to-days time))
((equal "." repeater-type)
;; Shift starting date to today.
(org-timestamp-change (- (org-today) (time-to-days time))
'day))
((equal (match-string 1 ts) "+")
((equal "+" repeater-type)
(let ((nshiftmax 10)
(nshift 0))
(while (or (= nshift 0)
(not (time-less-p (current-time) time)))
(when (= (cl-incf nshift) nshiftmax)
(when (= nshiftmax (cl-incf nshift))
(or (y-or-n-p
(format "%d repeater intervals were not \
enough to shift date past today. Continue? "
@ -12836,11 +12826,15 @@ enough to shift date past today. Continue? "
(save-excursion
(org-timestamp-change n (cdr (assoc what whata)) nil t))
(setq msg
(concat
msg type " " org-last-changed-timestamp " "))))))))
(concat msg type " " org-last-changed-timestamp " "))))
(t
;; Time-stamps without a repeater are usually skipped.
;; However, a SCHEDULED time-stamp without one is
;; removed, as they are no longer relevant.
(when (equal type org-scheduled-string)
(org-remove-timestamp-with-keyword type)))))))
(setq org-log-post-message msg)
(message "%s" msg))
(set-marker end nil))))
(message "%s" msg))))
(defun org-show-todo-tree (arg)
"Make a compact tree which shows all headlines marked with TODO.

View File

@ -6607,6 +6607,15 @@ Paragraph<point>"
(org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
(org-todo "DONE")
(buffer-string))))
;; Also repeat inactive time stamps with a repeater.
(should
(string-match-p
"\\[2014-03-29 .* \\+2y\\]"
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
(org-test-with-temp-text
"* TODO H\n[2012-03-29 Thu. +2y]"
(org-todo "DONE")
(buffer-string)))))
;; Do not repeat commented time stamps.
(should-not
(string-prefix-p