diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el index 43bf54e77..4dce3931f 100644 --- a/contrib/lisp/org-element.el +++ b/contrib/lisp/org-element.el @@ -1746,7 +1746,8 @@ and `:post-blank' keywords." (line-end-position) t) (goto-char (match-end 1)) (org-skip-whitespace) - (let ((time (buffer-substring-no-properties (point) (match-end 0))) + (let ((time (buffer-substring-no-properties + (1+ (point)) (1- (match-end 0)))) (keyword (match-string 1))) (cond ((equal keyword org-closed-string) (setq closed time)) ((equal keyword org-deadline-string) (setq deadline time)) @@ -1766,11 +1767,12 @@ CONTENTS is nil." 'identity (delq nil (list (let ((closed (org-element-property :closed planning))) - (when closed (concat org-closed-string " " closed))) + (when closed (concat org-closed-string " [" closed "]"))) (let ((deadline (org-element-property :deadline planning))) - (when deadline (concat org-deadline-string " " deadline))) + (when deadline (concat org-deadline-string " <" deadline ">"))) (let ((scheduled (org-element-property :scheduled planning))) - (when scheduled (concat org-scheduled-string " " scheduled))))) + (when scheduled + (concat org-scheduled-string " <" scheduled ">"))))) " ")) @@ -3069,24 +3071,24 @@ Return a list whose CAR is `timestamp', and CDR a plist with Assume point is at the beginning of the timestamp." (save-excursion (let* ((begin (point)) - (type (cond - ((looking-at org-tsr-regexp) - (if (match-string 2) 'active-range 'active)) - ((looking-at org-tsr-regexp-both) - (if (match-string 2) 'inactive-range 'inactive)) - ((looking-at - (concat - "\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)" - "\\|" - "\\(<%%\\(([^>\n]+)\\)>\\)")) - 'diary))) - (value (org-match-string-no-properties 0)) + (activep (eq (char-after) ?<)) + (main-value + (progn + (looking-at "[<[]\\(\\(%%\\)?.*?\\)[]>]\\(?:--[<[]\\(.*?\\)[]>]\\)?") + (match-string-no-properties 1))) + (range-end (match-string-no-properties 3)) + (type (cond ((match-string 2) 'diary) + ((and activep range-end) 'active-range) + (activep 'active) + (range-end 'inactive-range) + (t 'inactive))) (post-blank (progn (goto-char (match-end 0)) (skip-chars-forward " \t"))) (end (point))) (list 'timestamp (list :type type - :value value + :value main-value + :range-end range-end :begin begin :end end :post-blank post-blank))))) @@ -3094,7 +3096,13 @@ Assume point is at the beginning of the timestamp." (defun org-element-timestamp-interpreter (timestamp contents) "Interpret TIMESTAMP object as Org syntax. CONTENTS is nil." - (org-element-property :value timestamp)) + (let ((type (org-element-property :type timestamp) )) + (concat + (format (if (memq type '(inactive inactive-range)) "[%s]" "<%s>") + (org-element-property :value timestamp)) + (let ((range-end (org-element-property :range-end timestamp))) + (when range-end + (format (if (eq type 'inactive-range) "[%s]" "<%s>") range-end)))))) (defun org-element-timestamp-successor (limit) "Search for the next timestamp object. diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 11b9a671e..9412a19c3 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1141,21 +1141,21 @@ Outside list" :closed (org-test-with-temp-text "CLOSED: [2012-03-29 thu.]" (org-element-map (org-element-parse-buffer) 'planning 'identity nil t))) - "[2012-03-29 thu.]")) + "2012-03-29 thu.")) (should (equal (org-element-property :deadline (org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>" (org-element-map (org-element-parse-buffer) 'planning 'identity nil t))) - "<2012-03-29 thu.>")) + "2012-03-29 thu.")) (should (equal (org-element-property :scheduled (org-test-with-temp-text "SCHEDULED: <2012-03-29 thu.>" (org-element-map (org-element-parse-buffer) 'planning 'identity nil t))) - "<2012-03-29 thu.>"))) + "2012-03-29 thu."))) ;;;; Property Drawer @@ -1427,6 +1427,10 @@ Outside list" (should (org-test-with-temp-text "[2012-03-29 16:40]" (org-element-map (org-element-parse-buffer) 'timestamp 'identity))) + ;; Date range. + (should + (org-test-with-temp-text "[2012-03-29 16:40]--[2012-03-29 16:41]" + (org-element-map (org-element-parse-buffer) 'timestamp 'identity))) ;; Timestamps are not planning elements. (should-not (org-test-with-temp-text "SCHEDULED: <2012-03-29 16:40>" @@ -1781,9 +1785,9 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01")) (equal (org-test-parse-and-interpret "* Headline -CLOSED: <2012-01-01> DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>") +CLOSED: [2012-01-01] DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>") "* Headline -CLOSED: <2012-01-01> DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>\n")))) +CLOSED: [2012-01-01] DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>\n")))) (ert-deftest test-org-element/property-drawer-interpreter () "Test property drawer interpreter." @@ -1830,6 +1834,29 @@ CLOSED: <2012-01-01> DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>\n")))) "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2") "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2\n"))) +(ert-deftest test-org-element/timestamp-interpreter () + "Test timestamp interpreter." + ;; Active. + (should (equal (org-test-parse-and-interpret "<2012-03-29 16:40>") + "<2012-03-29 16:40>\n")) + ;; Inactive. + (should (equal (org-test-parse-and-interpret "[2012-03-29 16:40]") + "[2012-03-29 16:40]\n")) + ;; Active range. + (should (equal (org-test-parse-and-interpret + "<2012-03-29 16:40>--<2012-03-29 16:41>") + "<2012-03-29 16:40>--<2012-03-29 16:41>\n")) + ;; Inactive range. + (should (equal (org-test-parse-and-interpret + "[2012-03-29 16:40]--[2012-03-29 16:41]") + "[2012-03-29 16:40]--[2012-03-29 16:41]\n")) + ;; Diary. + (should (equal (org-test-parse-and-interpret "<%%org-float t 4 2>") + "<%%org-float t 4 2>\n")) + ;; Timestamp with repeater interval. + (should (equal (org-test-parse-and-interpret "<2012-03-29 +1y>") + "<2012-03-29 +1y>\n"))) + (ert-deftest test-org-element/verse-block-interpreter () "Test verse block interpretation." (should