* [PATCH] Fix ox-icalendar export of diary timestamps
@ 2024-09-15 6:26 Jack Kamm
2024-09-21 8:53 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages 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] 5+ messages in thread
* Re: [PATCH] Fix ox-icalendar export of diary timestamps
2024-09-15 6:26 [PATCH] Fix ox-icalendar export of diary timestamps Jack Kamm
@ 2024-09-21 8:53 ` Ihor Radchenko
2024-09-21 18:20 ` Jack Kamm
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2024-09-21 8:53 UTC (permalink / raw)
To: Jack Kamm; +Cc: emacs-orgmode
Jack Kamm <jackkamm@gmail.com> writes:
> 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.
I agree that it makes sense.
However, it is technically a breaking change.
May you please add a news entry as well?
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix ox-icalendar export of diary timestamps
2024-09-21 8:53 ` Ihor Radchenko
@ 2024-09-21 18:20 ` Jack Kamm
2024-09-22 10:25 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Jack Kamm @ 2024-09-21 18:20 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 224 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> I agree that it makes sense.
> However, it is technically a breaking change.
> May you please add a news entry as well?
Thanks, I've updated the patch with a news entry now.
[-- 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: 4014 bytes --]
From 5c40741664402a5984803dc3de452ea949885887 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.
---
etc/ORG-NEWS | 14 ++++++++++++++
lisp/ox-icalendar.el | 2 +-
lisp/ox.el | 2 +-
testing/lisp/test-ox-icalendar.el | 15 +++++++++++++++
4 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index a9357aa28..d31c62721 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -57,6 +57,20 @@ remote resources in the =#+include:='s. Now, an error is thrown to
avoid seemingly ignored =#+include= statements when publishing via
batch scripts.
+*** Diary-style timestamps are exported together with active timestamps
+
+~org-export-with-timestamps~ and ~org-icalendar-with-timestamps~ now
+treat diary-style timestamps as a type of active timestamp for
+purposes of export.
+
+This mainly affects iCalendar export, where diary timestamps will now
+be included when only active timestamps are exported (the default).
+
+This should have minimal impact on non-iCalendar exporters, since
+~org-export-with-timestamps~ was already ~t~ by default. However,
+users who manually set ~org-export-with-timestamps~ to ~active~ will
+now have diary timestamps included as well.
+
** New features
# We list the most important features, and the features that may
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] 5+ messages in thread
* Re: [PATCH] Fix ox-icalendar export of diary timestamps
2024-09-21 18:20 ` Jack Kamm
@ 2024-09-22 10:25 ` Ihor Radchenko
2025-01-12 21:35 ` Jack Kamm
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2024-09-22 10:25 UTC (permalink / raw)
To: Jack Kamm; +Cc: emacs-orgmode
Jack Kamm <jackkamm@gmail.com> writes:
> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> I agree that it makes sense.
>> However, it is technically a breaking change.
>> May you please add a news entry as well?
>
> Thanks, I've updated the patch with a news entry now.
Thanks!
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c07028671d
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix ox-icalendar export of diary timestamps
2024-09-22 10:25 ` Ihor Radchenko
@ 2025-01-12 21:35 ` Jack Kamm
0 siblings, 0 replies; 5+ messages in thread
From: Jack Kamm @ 2025-01-12 21:35 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 954 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> Jack Kamm <jackkamm@gmail.com> writes:
>
>> Ihor Radchenko <yantar92@posteo.net> writes:
>>
>>> I agree that it makes sense.
>>> However, it is technically a breaking change.
>>> May you please add a news entry as well?
>>
>> Thanks, I've updated the patch with a news entry now.
>
> Thanks!
> Applied, onto main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c07028671d
Hi, revisiting this old thread.
Unfortunately I found a case in the wild where this change caused a
temporary problem in org-caldav:
https://github.com/dengste/org-caldav/issues/315
I was able to fix the problem on org-caldav side, but it made me think
that I should have added an option to keep the old behavior (export
active timestamps excluding diary timestamps).
I attach a patch to do this, by adding an option `active-exclude-diary'
for `org-icalendar-with-timestamps' and `org-export-with-timestamps'.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-export-icalendar-with-timestamps-active-exclude-.patch --]
[-- Type: text/x-patch, Size: 8223 bytes --]
From d0b6c661528c5d7ae0f7fb3d393797aad2a291f8 Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@gmail.com>
Date: Sun, 12 Jan 2025 13:10:34 -0800
Subject: [PATCH] org-(export,icalendar)-with-timestamps: active-exclude-diary
option
* lisp/ox.el (org-export-with-timestamps): Add option
`active-exclude-diary' to export active timestamps without diary
timestamps.
(org-export--skip-p): Use new helper function
`org-export--skip-timestamp-p'.
(org-export--skip-timestamp-p): Helper function to decide whether
to skip a timestamp during export
* lisp/ox-icalendar.el (org-icalendar-with-timestamps): Add option
`active-exclude-diary' to export active timestamps without diary
timestamps.
(org-icalendar-entry): Use new helper function
`org-export--skip-timestamp-p' to decide whether to skip a timestamp.
* testing/lisp/test-ox-icalendar.el
(test-ox-icalendar/exclude-diary-timestamp): Test that diary timestamp
is excluded when `active-exclude-diary'.
---
etc/ORG-NEWS | 4 ++++
lisp/ox-icalendar.el | 29 ++++++++++++++---------
lisp/ox.el | 39 ++++++++++++++++++++-----------
testing/lisp/test-ox-icalendar.el | 15 ++++++++++++
4 files changed, 63 insertions(+), 24 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index aebd0dedd..3b86ece18 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -100,6 +100,10 @@ This should have minimal impact on non-iCalendar exporters, since
users who manually set ~org-export-with-timestamps~ to ~active~ will
now have diary timestamps included as well.
+To export active timestamps only without diary timestamps, users can
+set ~org-export-with-timestamps~ and ~org-icalendar-with-timestamps~
+to ~active-exclude-diary~.
+
*** =ob-calc.el=: Vector and matrix are now inserted as Org tables by default
~ob-calc~ now formats vector and matrix results as Org tables. This
diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index bb01f1a22..da6339381 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -202,18 +202,27 @@ (defcustom org-icalendar-categories '(local-tags category)
(defcustom org-icalendar-with-timestamps 'active
"Non-nil means make an event from plain time stamps.
-It can be set to `active', `inactive', t or nil, in order to make
-an event from, respectively, only active timestamps, only
-inactive ones, all of them or none.
+It can be set to `active', `active-exclude-diary', `inactive', t
+or nil, in order to make an event from, respectively, only active
+timestamps (with/without diary timestamps), only inactive ones,
+all of them or none.
+
+This variable has the same options as
+`org-export-with-timestamps', and takes precedence over it.
+However, note that this variable applies to all timestamps within
+an entry, whereas `org-export-with-timestamps' only applies to
+timestamps isolated in a paragraph containing only timestamps.
-This variable has precedence over `org-export-with-timestamps'.
It can also be set with the #+OPTIONS line, e.g. \"<:t\"."
:group 'org-export-icalendar
:type '(choice
(const :tag "All timestamps" t)
- (const :tag "Only active timestamps" active)
+ (const :tag "Active timestamps, including diary timestamps" active)
+ (const :tag "Active timestamps, excluding diary timestamps"
+ active-exclude-diary)
(const :tag "Only inactive timestamps" inactive)
- (const :tag "No timestamp" nil)))
+ (const :tag "No timestamp" nil))
+ :safe (lambda (x) (memq x '(t nil active active-exclude-diary inactive))))
(defcustom org-icalendar-include-todo nil
"Non-nil means create VTODO components from TODO items.
@@ -744,11 +753,9 @@ (defun org-icalendar-entry (entry contents info)
(org-element-contents inside))
'timestamp
(lambda (ts)
- (when (let ((type (org-element-property :type ts)))
- (cl-case (plist-get info :with-timestamps)
- (active (memq type '(active active-range diary)))
- (inactive (memq type '(inactive inactive-range)))
- ((t) t)))
+ (unless (org-export--skip-timestamp-p
+ (plist-get info :with-timestamps)
+ (org-element-property :type ts))
(let ((uid (format "TS%d-%s" (cl-incf counter) uid)))
(org-icalendar--vevent
entry ts uid summary loc desc cat tz class))))
diff --git a/lisp/ox.el b/lisp/ox.el
index 6ef0d2699..646d09b51 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -802,10 +802,11 @@ (defcustom org-export-with-timestamps t
"Non-nil means allow timestamps in export.
It can be set to any of the following values:
- t export all timestamps.
- `active' export active timestamps only.
- `inactive' export inactive timestamps only.
- nil do not export timestamps
+ t export all timestamps.
+ `active' export active timestamps, including diary timestamps.
+ `active-exclude-diary' export active timestamps, excluding diary timestamps.
+ `inactive' export inactive timestamps only.
+ nil do not export timestamps
This only applies to timestamps isolated in a paragraph
containing only timestamps. Other timestamps are always
@@ -816,10 +817,12 @@ (defcustom org-export-with-timestamps t
:group 'org-export-general
:type '(choice
(const :tag "All timestamps" t)
- (const :tag "Only active timestamps" active)
+ (const :tag "Active timestamps, including diary timestamps" active)
+ (const :tag "Active timestamps, excluding diary timestamps"
+ active-exclude-diary)
(const :tag "Only inactive timestamps" inactive)
(const :tag "No timestamp" nil))
- :safe (lambda (x) (memq x '(t nil active inactive))))
+ :safe (lambda (x) (memq x '(t nil active active-exclude-diary inactive))))
(defcustom org-export-with-todo-keywords t
"Non-nil means include TODO keywords in export.
@@ -1857,13 +1860,23 @@ (defun org-export--skip-p (datum options selected excluded)
(lambda (obj)
(or (not (stringp obj)) (org-string-nw-p obj)))
options t))))
- (cl-case (plist-get options :with-timestamps)
- ((nil) t)
- (active
- (not (memq (org-element-property :type datum) '(active active-range diary))))
- (inactive
- (not (memq (org-element-property :type datum)
- '(inactive inactive-range)))))))))
+ (org-export--skip-timestamp-p
+ (plist-get options :with-timestamps)
+ (org-element-property :type datum))))))
+
+(defun org-export--skip-timestamp-p (with-timestamps timestamp-type)
+ "Decides whether to skip a timestamp during export.
+WITH-TIMESTAMPS should be a valid option for
+`org-export-with-timestamps'. TIMESTAMP-TYPE should be the
+`:type' property of a timestamp element."
+ (cl-case with-timestamps
+ ((nil) t)
+ (active
+ (not (memq timestamp-type '(active active-range diary))))
+ (active-exclude-diary
+ (not (memq timestamp-type '(active active-range))))
+ (inactive
+ (not (memq timestamp-type '(inactive inactive-range))))))
\f
;;; The Transcoder
diff --git a/testing/lisp/test-ox-icalendar.el b/testing/lisp/test-ox-icalendar.el
index c7c74c526..8c0ab6377 100644
--- a/testing/lisp/test-ox-icalendar.el
+++ b/testing/lisp/test-ox-icalendar.el
@@ -143,5 +143,20 @@ (ert-deftest test-ox-icalendar/diary-timestamp ()
(should (search-forward "RRULE:FREQ=MONTHLY;BYDAY=1SU"))))
(when (file-exists-p tmp-ics) (delete-file tmp-ics)))))
+(ert-deftest test-ox-icalendar/exclude-diary-timestamp ()
+ "Test icalendar exclude of diary timestamps."
+ (let* ((org-icalendar-with-timestamps 'active-exclude-diary)
+ (tmp-ics (org-test-with-temp-text-in-file
+ "* Test entry with 2 timestamps
+<%%(diary-float t 0 1)>
+<2025-01-12 Sunday>"
+ (expand-file-name (org-icalendar-export-to-ics)))))
+ (unwind-protect
+ (with-temp-buffer
+ (insert-file-contents tmp-ics)
+ (save-excursion
+ (should (not (search-forward "RRULE:FREQ=MONTHLY;BYDAY=1SU" nil t)))))
+ (when (file-exists-p tmp-ics) (delete-file tmp-ics)))))
+
(provide 'test-ox-icalendar)
;;; test-ox-icalendar.el ends here
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-12 22:06 UTC | newest]
Thread overview: 5+ messages (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
2024-09-21 8:53 ` Ihor Radchenko
2024-09-21 18:20 ` Jack Kamm
2024-09-22 10:25 ` Ihor Radchenko
2025-01-12 21:35 ` 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).