summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-02-04 21:45:35 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-02-04 21:45:35 +0100
commit6632ce537e1ec575de3a09c23d8a0ca40dee1139 (patch)
tree86e67ea77793d185c2c5f597fee976d06b1409e5
parent737ada43c6539b6ae49550d474da7427a7120a2f (diff)
downloadorg-mode-6632ce537e1ec575de3a09c23d8a0ca40dee1139.tar.gz
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.
-rw-r--r--etc/ORG-NEWS4
-rw-r--r--lisp/org-habit.el2
-rw-r--r--lisp/org.el31
-rw-r--r--testing/lisp/test-org.el10
4 files changed, 34 insertions, 13 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 77ad2bc..ad70cc1 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -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
diff --git a/lisp/org-habit.el b/lisp/org-habit.el
index 1f61565..52a0628 100644
--- a/lisp/org-habit.el
+++ b/lisp/org-habit.el
@@ -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)
diff --git a/lisp/org.el b/lisp/org.el
index 619df32..19ad0a3 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 816b0e1..8f5210f 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -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."