emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix ox-icalendar export of diary timestamps
@ 2024-09-15  6:26 Jack Kamm
  0 siblings, 0 replies; only message in thread
From: Jack Kamm @ 2024-09-15  6:26 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

ox-icalendar skips the following event with a diary timestamp during
export:

  * First Sunday of the month
  <%%(diary-float t 0 1)>

ox-icalendar actually has longstanding code to handle diary timestamps
[1], but that code path is not reached, in part because
`org-export--skip-p' always skips timestamps with type `diary'.

The attached patch fixes this by including diary timestamps when the
export option `:with-timestamps' is `active'. I think it's reasonable
to consider diary timestamps as a type of active timestamp during
export, since they are included in the agenda, and have angle
brackets.

[1] https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ox-icalendar.el?id=07dd3bcae6b7b5e0692fc40dd307a7e841179b52#n826


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-icalendar-Fix-export-of-diary-style-timestamps.patch --]
[-- Type: text/x-patch, Size: 2962 bytes --]

From 32a5afd2803aa54e1e21b11d9d1e832e99538e9b Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@gmail.com>
Date: Sat, 14 Sep 2024 22:48:44 -0700
Subject: [PATCH] ox-icalendar: Fix export of diary-style timestamps

* lisp/ox-icalendar.el (org-icalendar-entry): Include timestamps of
type diary when `:with-timestamps' is `active'.
* lisp/ox.el (org-export--skip-p): Include timestamps of type diary
when `:with-timestamps' is `active'.
*
testing/lisp/test-ox-icalendar.el (test-ox-icalendar/diary-timestamp):
Unit test for exporting timestamps of type diary.
---
 lisp/ox-icalendar.el              |  2 +-
 lisp/ox.el                        |  2 +-
 testing/lisp/test-ox-icalendar.el | 15 +++++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 858d146d6..e7ca6aafb 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -746,7 +746,7 @@ (defun org-icalendar-entry (entry contents info)
 	       (lambda (ts)
 		 (when (let ((type (org-element-property :type ts)))
 			 (cl-case (plist-get info :with-timestamps)
-			   (active (memq type '(active active-range)))
+			   (active (memq type '(active active-range diary)))
 			   (inactive (memq type '(inactive inactive-range)))
 			   ((t) t)))
 		   (let ((uid (format "TS%d-%s" (cl-incf counter) uid)))
diff --git a/lisp/ox.el b/lisp/ox.el
index 7a0ab4dc7..79a1f5cfb 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1857,7 +1857,7 @@ (defun org-export--skip-p (datum options selected excluded)
        (cl-case (plist-get options :with-timestamps)
 	 ((nil) t)
 	 (active
-	  (not (memq (org-element-property :type datum) '(active active-range))))
+	  (not (memq (org-element-property :type datum) '(active active-range diary))))
 	 (inactive
 	  (not (memq (org-element-property :type datum)
 		     '(inactive inactive-range)))))))))
diff --git a/testing/lisp/test-ox-icalendar.el b/testing/lisp/test-ox-icalendar.el
index e631b2119..c7c74c526 100644
--- a/testing/lisp/test-ox-icalendar.el
+++ b/testing/lisp/test-ox-icalendar.el
@@ -128,5 +128,20 @@ (ert-deftest test-ox-icalendar/warn-unsupported-repeater ()
          (when (file-exists-p tmp-ics)
            (delete-file tmp-ics))))))))
 
+(ert-deftest test-ox-icalendar/diary-timestamp ()
+  "Test icalendar export of diary timestamps."
+  (let* ((tmp-ics (org-test-with-temp-text-in-file
+                   "* First Sunday of the month
+<%%(diary-float t 0 1)>"
+                   (expand-file-name (org-icalendar-export-to-ics)))))
+    (unwind-protect
+        (with-temp-buffer
+          (insert-file-contents tmp-ics)
+          (save-excursion
+            (should (search-forward "SUMMARY:First Sunday of the month")))
+          (save-excursion
+            (should (search-forward "RRULE:FREQ=MONTHLY;BYDAY=1SU"))))
+      (when (file-exists-p tmp-ics) (delete-file tmp-ics)))))
+
 (provide 'test-ox-icalendar)
 ;;; test-ox-icalendar.el ends here
-- 
2.46.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-09-15  6:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-15  6:26 [PATCH] Fix ox-icalendar export of diary timestamps Jack Kamm

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).