1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

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
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
*** ~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))
(cl-assert (org-is-habit-p (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))
(habit-entry (org-no-properties (nth 4 (org-heading-components))))
closed-dates deadline dr-days sr-days sr-type)

View File

@ -13194,18 +13194,27 @@ on INACTIVE-OK."
(throw 'exit t)))
nil)))
(defun org-get-repeat (&optional tagline)
"Check if there is a deadline/schedule with repeater in this entry."
(defun org-get-repeat (&optional timestamp)
"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-excursion
(org-back-to-heading t)
(let ((end (org-entry-end-position))
(regexp (if tagline (concat tagline "\\s-*" org-repeat-re)
org-repeat-re)))
(catch :repeat
(while (re-search-forward regexp end t)
(when (save-match-data (org-at-timestamp-p))
(throw :repeat (match-string-no-properties 1)))))))))
(cond (timestamp
(and (string-match org-repeat-re timestamp)
(match-string-no-properties 1 timestamp)))
((org-before-first-heading-p) nil)
(t
(save-excursion
(org-back-to-heading t)
(let ((end (org-entry-end-position)))
(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-inserted-timestamp)

View File

@ -5615,7 +5615,15 @@ Paragraph<point>"
(should-not
(org-test-with-temp-text
"* 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 ()
"Test `org-timestamp-format' specifications."