Change `org-get-repeater' signature

* lisp/org.el (org-get-repeater): Change optional argument meaning.
* lisp/org-habit.el (org-habit-parse-todo): Apply signature change.
* testing/test-org.el (test-org/get-repeater): Add tests.
This commit is contained in:
Nicolas Goaziou 2017-02-04 21:45:35 +01:00
parent 737ada43c6
commit 6632ce537e
4 changed files with 34 additions and 13 deletions

View File

@ -62,6 +62,10 @@ to the following
~:istart~, ~:icount~, ~:iend~ and ~:isep~ now expect the type of the ~:istart~, ~:icount~, ~:iend~ and ~:isep~ now expect the type of the
list as their first argument. list as their first argument.
*** Change signature for ~org-get-repeater~
The optional argument is now a string to extract the repeater from.
See docstring for details.
** New features ** New features
*** ~org-edit-special~ can edit LaTeX environments *** ~org-edit-special~ can edit LaTeX environments

View File

@ -170,7 +170,7 @@ This list represents a \"habit\" for the rest of this module."
(if pom (goto-char pom)) (if pom (goto-char pom))
(cl-assert (org-is-habit-p (point))) (cl-assert (org-is-habit-p (point)))
(let* ((scheduled (org-get-scheduled-time (point))) (let* ((scheduled (org-get-scheduled-time (point)))
(scheduled-repeat (org-get-repeat org-scheduled-string)) (scheduled-repeat (org-get-repeat (org-entry-get (point) "SCHEDULED")))
(end (org-entry-end-position)) (end (org-entry-end-position))
(habit-entry (org-no-properties (nth 4 (org-heading-components)))) (habit-entry (org-no-properties (nth 4 (org-heading-components))))
closed-dates deadline dr-days sr-days sr-type) closed-dates deadline dr-days sr-days sr-type)

View File

@ -13194,18 +13194,27 @@ on INACTIVE-OK."
(throw 'exit t))) (throw 'exit t)))
nil))) nil)))
(defun org-get-repeat (&optional tagline) (defun org-get-repeat (&optional timestamp)
"Check if there is a deadline/schedule with repeater in this entry." "Check if there is a time-stamp with repeater in this entry.
Return the repeater, as a string, or nil. Also return nil when
this function is called before first heading.
When optional argument TIMESTAMP is a string, extract the
repeater from there instead."
(save-match-data (save-match-data
(save-excursion (cond (timestamp
(org-back-to-heading t) (and (string-match org-repeat-re timestamp)
(let ((end (org-entry-end-position)) (match-string-no-properties 1 timestamp)))
(regexp (if tagline (concat tagline "\\s-*" org-repeat-re) ((org-before-first-heading-p) nil)
org-repeat-re))) (t
(catch :repeat (save-excursion
(while (re-search-forward regexp end t) (org-back-to-heading t)
(when (save-match-data (org-at-timestamp-p)) (let ((end (org-entry-end-position)))
(throw :repeat (match-string-no-properties 1))))))))) (catch :repeat
(while (re-search-forward org-repeat-re end t)
(when (save-match-data (org-at-timestamp-p))
(throw :repeat (match-string-no-properties 1)))))))))))
(defvar org-last-changed-timestamp) (defvar org-last-changed-timestamp)
(defvar org-last-inserted-timestamp) (defvar org-last-inserted-timestamp)

View File

@ -5615,7 +5615,15 @@ Paragraph<point>"
(should-not (should-not
(org-test-with-temp-text (org-test-with-temp-text
"* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE" "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
(org-get-repeat)))) (org-get-repeat)))
;; Return nil when called before first heading.
(should-not
(org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
(org-get-repeat)))
;; When called with an optional argument, extract repeater from that
;; string instead.
(should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
(should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
(ert-deftest test-org/timestamp-format () (ert-deftest test-org/timestamp-format ()
"Test `org-timestamp-format' specifications." "Test `org-timestamp-format' specifications."