emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-icalendar.el: create alarm at event time
@ 2021-12-25 15:24 Mikhail Skorzhinskii
  2021-12-26 21:22 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-25 15:24 UTC (permalink / raw)
  To: Org Mode


* lisp/ox-icalendar.el (org-icalendar-force-alarm): option to set alarm
even if alarm time is set to zero.
* lisp/ox-icalendar.el (org-icalendar--valarm): create VALARM at the
event start if the alarm time is set to zero and
`org-icalendar-force-alarm' is set to true.
---
 lisp/ox-icalendar.el | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 0a56e08e5..15b5e3e37 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -66,6 +66,15 @@ for timed events.  If non-zero, alarms are created.
   :version "24.1"
   :type 'integer)
 
+(defcustom org-icalendar-force-alarm nil
+  "Non-nil means alarm will be created even if is set to zero.
+
+This overrides default behaviour where zero means no alarm. With
+this set to non-nil and alarm set to zero, alarm will be created
+and will fire at the event start."
+  :group 'org-export-icalendar
+  :type 'bool)
+
 (defcustom org-icalendar-combined-name "OrgMode"
   "Calendar name for the combined iCalendar representing all agenda
files."
   :group 'org-export-icalendar
@@ -803,8 +812,11 @@ Return VALARM component as a string, or nil if it
isn't allowed."
   (let ((alarm-time
         (let ((warntime
                (org-element-property :APPT_WARNTIME entry)))
-          (if warntime (string-to-number warntime) 0))))
-    (and (or (> alarm-time 0) (> org-icalendar-alarm-time 0))
+          (if warntime (string-to-number warntime) nil))))
+    (and (or (and alarm-time
+                 (> alarm-time 0))
+            (> org-icalendar-alarm-time 0)
+            org-icalendar-force-alarm)
         (org-element-property :hour-start timestamp)
         (format "BEGIN:VALARM
 ACTION:DISPLAY
@@ -812,7 +824,13 @@ DESCRIPTION:%s
 TRIGGER:-P0DT0H%dM0S
 END:VALARM\n"
                 summary
-                (if (zerop alarm-time) org-icalendar-alarm-time alarm-
time)))))
+                (if org-icalendar-force-alarm
+                    (if alarm-time
+                        alarm-time
+                      org-icalendar-alarm-time)
+                  (if (zerop alarm-time)
+                      org-icalendar-alarm-time
+                    alarm-time))))))
 
 
 ;;;; Template



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ox-icalendar.el: create alarm at event time
  2021-12-25 15:24 [PATCH] ox-icalendar.el: create alarm at event time Mikhail Skorzhinskii
@ 2021-12-26 21:22 ` Nicolas Goaziou
  2021-12-28 12:08   ` Mikhail Skorzhinskii
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2021-12-26 21:22 UTC (permalink / raw)
  To: Mikhail Skorzhinskii; +Cc: Org Mode

Hello,

Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:

> * lisp/ox-icalendar.el (org-icalendar-force-alarm): option to set alarm
> even if alarm time is set to zero.
> * lisp/ox-icalendar.el (org-icalendar--valarm): create VALARM at the
> event start if the alarm time is set to zero and
> `org-icalendar-force-alarm' is set to true.

Thanks. Some comments follow.

> +(defcustom org-icalendar-force-alarm nil
> +  "Non-nil means alarm will be created even if is set to zero.
> +
> +This overrides default behaviour where zero means no alarm. With
                                                             ^^^
You need two spaces after full stop.

> +this set to non-nil and alarm set to zero, alarm will be created
> +and will fire at the event start."
> +  :group 'org-export-icalendar
> +  :type 'bool)

`boolean' is the valid type.

You also need to add :package-version '(Org . "9.6") and :safe #'booleanp.
> +                (if org-icalendar-force-alarm
> +                    (if alarm-time
> +                        alarm-time
> +                      org-icalendar-alarm-time)
> +                  (if (zerop alarm-time)
> +                      org-icalendar-alarm-time
> +                    alarm-time))))))

I suggest to refactor the above into something like:

(cond
 ((> alarm-time 0) alarm-time)
 ((and (= 0 alarm-time) org-icalendar-force-alarm) alarm-time)
 (t org-icalendar-alarm-time))

Could you send an updated patch?

Regards,
-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ox-icalendar.el: create alarm at event time
  2021-12-26 21:22 ` Nicolas Goaziou
@ 2021-12-28 12:08   ` Mikhail Skorzhinskii
  2022-07-31  7:07     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-28 12:08 UTC (permalink / raw)
  To: Org Mode

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

Hi Nicolas,

Thank you for the review, appreciate your comments. I've applied your
suggestions. Please find the fixed file in the attachment to this
letter.

There is one important note that about this patch. There is one corner
case: when we've set org-icalendar-force-alarm variable to nil, org-
icalendar-alarm-time variable to non-nil and the APPT_WARNTIME property
is set to 0, then, with my code, the value of the org-icalendar-alarm-
time would be used.

Basically if user is not forcing the 'zero alarms', and has some non-
zero default value for alarms, the APPT_WARNTIME property will use
default alarm. Which is something, I would say, unexpected. I would
expect that alarm will be shut-off.

However I am just keeping the previous behaviour. I think its worth
fixing, but I'd say we do this in a separate patch.

Let me know what you think.

Thanks,
Mikhail

On Sun, 2021-12-26 at 22:22 +0100, Nicolas Goaziou wrote:
> Hello,
> 
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
> 
> > * lisp/ox-icalendar.el (org-icalendar-force-alarm): option to set
> > alarm
> > even if alarm time is set to zero.
> > * lisp/ox-icalendar.el (org-icalendar--valarm): create VALARM at
> > the
> > event start if the alarm time is set to zero and
> > `org-icalendar-force-alarm' is set to true.
> 
> Thanks. Some comments follow.
> 
> > +(defcustom org-icalendar-force-alarm nil
> > +  "Non-nil means alarm will be created even if is set to zero.
> > +
> > +This overrides default behaviour where zero means no alarm. With
>                                                              ^^^
> You need two spaces after full stop.
> 
> > +this set to non-nil and alarm set to zero, alarm will be created
> > +and will fire at the event start."
> > +  :group 'org-export-icalendar
> > +  :type 'bool)
> 
> `boolean' is the valid type.
> 
> You also need to add :package-version '(Org . "9.6") and :safe
> #'booleanp.
> > +                (if org-icalendar-force-alarm
> > +                    (if alarm-time
> > +                        alarm-time
> > +                      org-icalendar-alarm-time)
> > +                  (if (zerop alarm-time)
> > +                      org-icalendar-alarm-time
> > +                    alarm-time))))))
> 
> I suggest to refactor the above into something like:
> 
> (cond
>  ((> alarm-time 0) alarm-time)
>  ((and (= 0 alarm-time) org-icalendar-force-alarm) alarm-time)
>  (t org-icalendar-alarm-time))
> 
> Could you send an updated patch?
> 
> Regards,
> -- 
> Nicolas Goaziou

[-- Attachment #2: 0004-ox-icalendar.el-create-alarm-at-event-time.patch --]
[-- Type: text/x-patch, Size: 2372 bytes --]

From 39b0df3309607f61d108402748d6646939f98696 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskiy@eml.cc>
Date: Sat, 12 Sep 2020 18:52:39 +0200
Subject: [PATCH 4/5] ox-icalendar.el: create alarm at event time

* lisp/ox-icalendar.el (org-icalendar-force-alarm): option to set alarm
even if alarm time is set to zero.
* lisp/ox-icalendar.el (org-icalendar--valarm): create VALARM at the
event start if the alarm time is set to zero and
`org-icalendar-force-alarm' is set to true.
---
 lisp/ox-icalendar.el | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 189e35946..1870a72b8 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -66,6 +66,17 @@ for timed events.  If non-zero, alarms are created.
   :version "24.1"
   :type 'integer)
 
+(defcustom org-icalendar-force-alarm nil
+  "Non-nil means alarm will be created even if is set to zero.
+
+This overrides default behaviour where zero means no alarm.  With
+this set to non-nil and alarm set to zero, alarm will be created
+and will fire at the event start."
+  :group 'org-export-icalendar
+  :type 'boolean
+  :package-version '(Org . "9.6")
+  :safe #'booleanp)
+
 (defcustom org-icalendar-combined-name "OrgMode"
   "Calendar name for the combined iCalendar representing all agenda files."
   :group 'org-export-icalendar
@@ -807,8 +818,11 @@ Return VALARM component as a string, or nil if it isn't allowed."
   (let ((alarm-time
 	 (let ((warntime
 		(org-element-property :APPT_WARNTIME entry)))
-	   (if warntime (string-to-number warntime) 0))))
-    (and (or (> alarm-time 0) (> org-icalendar-alarm-time 0))
+	   (if warntime (string-to-number warntime) nil))))
+    (and (or (and alarm-time
+		  (> alarm-time 0))
+	     (> org-icalendar-alarm-time 0)
+	     org-icalendar-force-alarm)
 	 (org-element-property :hour-start timestamp)
 	 (format "BEGIN:VALARM
 ACTION:DISPLAY
@@ -816,8 +830,10 @@ DESCRIPTION:%s
 TRIGGER:-P0DT0H%dM0S
 END:VALARM\n"
 		 summary
-		 (if (zerop alarm-time) org-icalendar-alarm-time alarm-time)))))
-
+                 (cond
+                  ((and alarm-time org-icalendar-force-alarm) alarm-time)
+                  ((and alarm-time (not (zerop alarm-time))) alarm-time)
+                  (t org-icalendar-alarm-time))))))
 
 ;;;; Template
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ox-icalendar.el: create alarm at event time
  2021-12-28 12:08   ` Mikhail Skorzhinskii
@ 2022-07-31  7:07     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2022-07-31  7:07 UTC (permalink / raw)
  To: Mikhail Skorzhinskii; +Cc: Org Mode

Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:

> Thank you for the review, appreciate your comments. I've applied your
> suggestions. Please find the fixed file in the attachment to this
> letter.

It took a while, but
Applied onto main via 31b3b164d after adding a TINYCHANGE cookie to the
commit message (AFAIK, you haven't signed the FSF copyright assignment).
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=31b3b164d100362365bd301d44a838cdf1059109

> There is one important note that about this patch. There is one corner
> case: when we've set org-icalendar-force-alarm variable to nil, org-
> icalendar-alarm-time variable to non-nil and the APPT_WARNTIME property
> is set to 0, then, with my code, the value of the org-icalendar-alarm-
> time would be used.
>
> Basically if user is not forcing the 'zero alarms', and has some non-
> zero default value for alarms, the APPT_WARNTIME property will use
> default alarm. Which is something, I would say, unexpected. I would
> expect that alarm will be shut-off.
>
> However I am just keeping the previous behaviour. I think its worth
> fixing, but I'd say we do this in a separate patch.

Sounds reasonable. Feel free to share a patch if you are still
interested. However, note that you applied patch is ~15LOC and FSF
copyright assignment may be needed. See
https://orgmode.org/worg/org-contribute.html#copyright

Best,
Ihor



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-31  7:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-25 15:24 [PATCH] ox-icalendar.el: create alarm at event time Mikhail Skorzhinskii
2021-12-26 21:22 ` Nicolas Goaziou
2021-12-28 12:08   ` Mikhail Skorzhinskii
2022-07-31  7:07     ` Ihor Radchenko

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).