summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-10-13 10:17:16 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2013-10-13 10:17:16 +0200
commit11514badc127a23be25c12394a5084f0e83e8f09 (patch)
tree42783ddad1b9d6b4f273d7b74b970219bc43ec7f
parent0eb0e5778bb61d6364acd6a11516c7e4df3b3b62 (diff)
downloadorg-mode-11514badc127a23be25c12394a5084f0e83e8f09.tar.gz
org-element: Parse warning delays in timestamps
* lisp/org-element.el (org-element-timestamp-parser, org-element-timestamp-interpreter): Parse warning delays. * testing/lisp/test-org-element.el (test-org-element/timestamp): Add tests.
-rw-r--r--lisp/org-element.el30
-rw-r--r--testing/lisp/test-org-element.el12
2 files changed, 38 insertions, 4 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 807fdb4..62461f7 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -3549,7 +3549,12 @@ beginning position."
"Parse time stamp at point.
Return a list whose CAR is `timestamp', and CDR a plist with
-`:type', `:begin', `:end', `:value' and `:post-blank' keywords.
+`:type', `:raw-value', `:year-start', `:month-start',
+`:day-start', `:hour-start', `:minute-start', `:year-end',
+`:month-end', `:day-end', `:hour-end', `:minute-end',
+`:repeater-type', `:repeater-value', `:repeater-unit',
+`:warning-type', `:warning-value', `:warning-unit', `:begin',
+`:end', `:value' and `:post-blank' keywords.
Assume point is at the beginning of the timestamp."
(save-excursion
@@ -3579,7 +3584,7 @@ Assume point is at the beginning of the timestamp."
(t 'inactive)))
(repeater-props
(and (not diaryp)
- (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)>"
+ (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)"
raw-value)
(list
:repeater-type
@@ -3591,6 +3596,15 @@ Assume point is at the beginning of the timestamp."
:repeater-unit
(case (string-to-char (match-string 3 raw-value))
(?h 'hour) (?d 'day) (?w 'week) (?m 'month) (t 'year)))))
+ (warning-props
+ (and (not diaryp)
+ (string-match "\\(-\\)?-\\([0-9]+\\)\\([hdwmy]\\)" raw-value)
+ (list
+ :warning-type (if (match-string 1 raw-value) 'first 'all)
+ :warning-value (string-to-number (match-string 2 raw-value))
+ :warning-unit
+ (case (string-to-char (match-string 3 raw-value))
+ (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (t 'year)))))
year-start month-start day-start hour-start minute-start year-end
month-end day-end hour-end minute-end)
;; Parse date-start.
@@ -3627,7 +3641,8 @@ Assume point is at the beginning of the timestamp."
:begin begin
:end end
:post-blank post-blank)
- repeater-props)))))
+ repeater-props
+ warning-props)))))
(defun org-element-timestamp-interpreter (timestamp contents)
"Interpret TIMESTAMP object as Org syntax.
@@ -3643,6 +3658,15 @@ CONTENTS is nil."
(and val (number-to-string val)))
(case (org-element-property :repeater-unit timestamp)
(hour "h") (day "d") (week "w") (month "m") (year "y"))))
+ (warning-string
+ (concat
+ (and (eq (org-element-property :warninger-type timestamp) 'first)
+ "-")
+ "-"
+ (let ((val (org-element-property :warninger-value timestamp)))
+ (and val (number-to-string val)))
+ (case (org-element-property :warninger-unit timestamp)
+ (hour "h") (day "d") (week "w") (month "m") (year "y"))))
(build-ts-string
;; Build an Org timestamp string from TIME. ACTIVEP is
;; non-nil when time stamp is active. If WITH-TIME-P is
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index ea4f649..b124f71 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1921,11 +1921,21 @@ Outside list"
(let ((timestamp (org-element-context)))
(or (org-element-property :hour-end timestamp)
(org-element-property :minute-end timestamp)))))
- ;; With repeater.
+ ;; With repeater, warning delay and both.
(should
(eq 'catch-up
(org-test-with-temp-text "<2012-03-29 Thu ++1y>"
(org-element-property :repeater-type (org-element-context)))))
+ (should
+ (eq 'first
+ (org-test-with-temp-text "<2012-03-29 Thu --1y>"
+ (org-element-property :warning-type (org-element-context)))))
+ (should
+ (equal '(cumulate all)
+ (org-test-with-temp-text "<2012-03-29 Thu +1y -1y>"
+ (let ((ts (org-element-context)))
+ (list (org-element-property :repeater-type ts)
+ (org-element-property :warning-type ts))))))
;; Timestamps are not planning elements.
(should-not
(org-test-with-temp-text "SCHEDULED: <2012-03-29 Thu 16:40>"