emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Michaël Cadilhac" <michael@cadilhac.name>
To: "Michaël Cadilhac" <michael@cadilhac.name>, emacs-orgmode@gnu.org
Subject: Re: org-icalendar: Change dates to today in VEVENT export
Date: Wed, 28 Aug 2019 17:54:51 -0500	[thread overview]
Message-ID: <CADt3fpNqAVDmCHkCSrYaTtpxqCFqQ_c8NNH35iiJJfbFYKuBnQ@mail.gmail.com> (raw)
In-Reply-To: <87pnrx4d77.fsf@nicolasgoaziou.fr>


[-- Attachment #1.1: Type: text/plain, Size: 5778 bytes --]

Hopefully I didn't miss anything—I've been running the patched version for
weeks now, so it should be stable in any case.  Patch 0003 above should
still be OK.

Cheers,
M.


On Tue, 12 Feb 2019 at 02:34, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Michaël Cadilhac <michael@cadilhac.name> writes:
>
> > Well, certainly.  I may not have had the best discipline in writing
> > these, so turning them into patches is a bit painful.  Let me know if
> > I can make things better.  (I believe my FSF paperwork is still
> > alright, if need be.)
>
> Thank you! Comments follow.
>
> > +(defcustom org-icalendar-bump-todos nil
> > +  "Non-nil means that pending TODO VEVENTs are bumped to today.
> > +In addition, if non-nil, the number of late days is indicated in the
> summary."
> > +  :group 'org-export-icalendar
> > +  :type 'boolean)
>
> This variable is missing :package-version '(Org . "9.3") and :safe
> keywords.  This is also true for other defcustom introduced throughout
> your patches.
>
> > +(defun org-icalendar-today-timestamp ()
> > +  "Return a TIMESTAMP object for today, at 00:00."
> > +  (let ((dt (decode-time)))
> > +    (list 'timestamp
> > +       (nconc (list :year-start (nth 5 dt)
> > +                    :year-end (nth 5 dt)
> > +                    :month-start (nth 4 dt)
> > +                    :month-end (nth 4 dt)
> > +                    :day-start (nth 3 dt)
> > +                    :day-end (nth 3 dt))))))
>
> This function already exists: `org-timestamp-from-time'.
>
> > +(defun org-icalendar-days-until-timestamp (timestamp)
> > +  "Return the number of days until TIMESTAMP.
> > +
> > +If TIMESTAMP occurs today, return 0.
> > +If TIMESTAMP occurs yesterday, return -1."
> > +  (floor
> > +   (/ (float-time
> > +       (time-subtract (org-timestamp--to-internal-time timestamp)
> > +                   (apply 'encode-time
> > +                          (append '(0 0 0) (nthcdr 3 (decode-time))))))
>
>     (time-substract (org-timestamp-to-time timestamp)
>                     (current-time))
>
> > +      (* 60 60 24))))
> >
> > -               (concat "DL: " summary) loc desc cat tz class)))
> > +                (concat "DL: " summary) loc desc cat tz class))
> > +
>
> Spurious blank line.
>
> > +              ;; Case 2: pending TODO overdue and should bump.
> > +              ((and org-icalendar-bump-todos
> > +                    (< days-until-deadline 0))
> > +               (org-icalendar--vevent
> > +                entry (org-icalendar-today-timestamp) (concat "DL-" uid)
> > +                (concat "DL (" (number-to-string (-
> days-until-deadline))
> > +                        "x): " summary)
>
> Nitpick:
>
>   (format "DL (%d)x): %s" (- days-until-deadline) summary
>
> is more readable.
>
> > +                loc desc cat tz class))
> > +              ;; Case 3: in the future and should warn.
> > +              (t
> > +               (concat
> > +                ;; If in the warning zone.
> > +                (when (<= days-until-deadline org-deadline-warning-days)
> > +                  (org-icalendar--vevent
> > +                   entry (org-icalendar-today-timestamp) (concat "DL-"
> uid)
> > +                   (concat "DL (in " (number-to-string
> days-until-deadline)
> > +                           "d.): " summary)
>
> See above.
>
> > +              ;; Overdue and should bump.
> > +              (t
> > +               (org-icalendar--vevent
> > +                entry (org-icalendar-today-timestamp) (concat "SC-" uid)
> > +                (concat "S (" (number-to-string (-
> days-until-scheduled)) "x): "
> > +                        summary)
>
> Ditto.
>
> > Subject: [PATCH 2/6] Include tags in SUMMARY if so desired.
>
> I'm ignoring this patch since it is superseded by the fifth.  Could you
> merge them?
>
> >  #+vindex: org-icalendar-categories
> >  #+vindex: org-icalendar-alarm-time
> > +#+vindex: org-icalendar-summary-uses-tags
> >  For tags on the headline, the iCalendar export back-end makes them
> >  into iCalendar categories.  To tweak the inheritance of tags and TODO
> >  states, configure the variable ~org-icalendar-categories~.  To assign
> >  clock alarms based on time, configure the ~org-icalendar-alarm-time~
> > -variable.
> > +variable.  Additionally, the variable
> > +~org-icalendar-summary-uses-tags~ can be configured to have tags
> > +appear in the title of the event, when SUMMARY is not provided.
>
> I think this should go near the paragraph about
> `org-calendar-include-body'.
>
> >  (defcustom org-icalendar-summary-uses-tags nil
> > -  "Non-nil means that TITLE+TAGS is used when SUMMARY is not provided.
> > -If nil, then TITLE is used alone."
> > +  "Whether tags should be added to the title to create the summary.
>
> Nitpick.
>
> "Non-nil means" > "Whether" because it is more unambiguously informative
>
>   When non-nil, tags are added to ...
>
> or
>
>   Non-nil means tags are added to ...
>
> >          (let ((tags (apply 'concat
> > -                           (mapcar (lambda (x) (concat ":" x))
> > -                                   (org-export-get-tags entry info nil
> t)))))
> > +                           (mapcar
> > +                            (lambda (x) (concat ":" x))
> > +                            (org-export-get-tags
> > +                             entry info nil
> > +                             (eq org-icalendar-summary-uses-tags
> 'all-tags))))))
>
>     (apply 'concat (lambda ...) ...) => (mapconcat (lambda ...) ...)
>
> Could you send an updated patch series?
>
> Thank you again.
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #1.2: Type: text/html, Size: 7454 bytes --]

[-- Attachment #2: 0001-Allow-tags-to-be-part-of-the-summary-in-iCal-export.patch --]
[-- Type: text/x-patch, Size: 3022 bytes --]

From 27c6f3fc2b278aded83d364f8924dcf2d96601c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Cadilhac?= <michael@cadilhac.name>
Date: Wed, 14 Aug 2019 19:55:07 -0400
Subject: [PATCH] Allow tags to be part of the summary in iCal export

* lisp/ox-icalendar.el (org-icalendar-summary-uses-tags): Introduce
new variable to include tags in summaries.
(org-icalendar-entry): Implement it.
* doc/org-manual.org (iCalendar Export): Document
org-icalendar-summary-uses-tags.
---
 doc/org-manual.org   |  4 +++-
 lisp/ox-icalendar.el | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index c0a91ab3e..7d9f9df61 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -15248,7 +15248,9 @@ For tags on the headline, the iCalendar export back-end makes them
 into iCalendar categories.  To tweak the inheritance of tags and TODO
 states, configure the variable ~org-icalendar-categories~.  To assign
 clock alarms based on time, configure the ~org-icalendar-alarm-time~
-variable.
+variable.  Additionally, the variable
+~org-icalendar-summary-uses-tags~ can be configured to have tags
+appear in the title of the event, when SUMMARY is not provided.
 
 #+vindex: org-icalendar-store-UID
 #+cindex: @samp{ID}, property
diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 779051cb0..9f1c0d43f 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -119,6 +119,21 @@ This is a list with possibly several symbols in it.  Valid symbols are:
 	      (const :tag "SCHEDULED in TODO entries become start date"
 		     todo-start)))
 
+(defcustom org-icalendar-summary-uses-tags nil
+  "Whether tags should be added to the title to create the summary.
+
+If a SUMMARY is provided in the entry, this is irrelevant.
+If non-nil, it can be set to `local-tags' or `all-tags' indicating which tags
+are used to make up the summary: only tags defined in the current line or all
+tags including inherited ones, respectively."
+  :group 'org-export-icalendar
+  :type '(choice
+	  (const :tag "Use the tags defined in current line" local-tags)
+	  (const :tag "Use all tags, including inherited ones" all-tags)
+	  (const :tag "Do not use tags in summary" nil)))
+
+
+
 (defcustom org-icalendar-categories '(local-tags category)
   "Items that should be entered into the \"categories\" field.
 
@@ -562,6 +577,15 @@ inlinetask within the section."
 	     (tz (org-export-get-node-property
 		  :TIMEZONE entry
 		  (org-property-inherit-p "TIMEZONE"))))
+	 (when (and org-icalendar-summary-uses-tags
+		    (not (org-element-property :SUMMARY entry)))
+	   (let ((tags (mapconcat
+			(lambda (x) (concat ":" x))
+			(org-export-get-tags
+			 entry info nil
+			 (eq org-icalendar-summary-uses-tags 'all-tags)))))
+	     (when tags
+	       (setq summary (concat summary " " tags ":")))))
 	 (concat
 	  ;; Events: Delegate to `org-icalendar--vevent' to generate
 	  ;; "VEVENT" component from scheduled, deadline, or any
-- 
2.22.0


[-- Attachment #3: 0001-Allow-bumping-late-tasks-and-warning-deadlines-in-iC.patch --]
[-- Type: text/x-patch, Size: 7169 bytes --]

From 78c9298375942d73543aaa86b8f2af29ff76a9df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Cadilhac?= <michael@cadilhac.name>
Date: Thu, 15 Aug 2019 10:01:48 -0400
Subject: [PATCH] Allow bumping late tasks and warning deadlines in iCal export

* lisp/ox-icalendar.el (org-icalendar-bump-todos): New variable.
(org-icalendar-warn-deadlines): New variable.
(org-icalendar-today-timestamp): New function.
(org-icalendar-days-until-timestamp): New function.
(org-icalendar-entry): Implement bumping late tasks and warning deadlines.
* doc/org-manual.org (iCalendar Export): Document this.
---
 doc/org-manual.org   |  12 +++++
 lisp/ox-icalendar.el | 114 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 113 insertions(+), 13 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index c0a91ab3e..9dc58247b 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -15329,6 +15329,18 @@ capabilities of the destination application.  Some are more lenient
 than others.  Consult the Org mode FAQ for advice on specific
 applications.
 
+#+vindex: org-icalendar-bump-todos
+#+vindex: org-icalendar-warn-deadlines
+An important difference between the Org Agenda and the exported
+calendar is that overdue tasks and deadline warnings are not treated
+in any special way by default.  To change this, configure the
+variables ~org-icalendar-bump-todos~ and
+~org-icalendar-warn-deadlines~.  Setting the first variable will move
+overdue TODOs to the current day, their titles being changed to
+reflect how late the task is.  Setting the second variable adds an
+event on the current day if a deadline event is due in the next
+~org-deadline-warning-days~ days.
+
 ** Other Built-in Back-ends
 :PROPERTIES:
 :DESCRIPTION: Exporting to a man page.
diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 779051cb0..3a291ee2b 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -119,6 +119,24 @@ This is a list with possibly several symbols in it.  Valid symbols are:
 	      (const :tag "SCHEDULED in TODO entries become start date"
 		     todo-start)))
 
+(defcustom org-icalendar-bump-todos nil
+  "Non-nil means that pending TODO VEVENTs are bumped to today.
+In addition, if non-nil, the number of late days is indicated in the summary."
+  :group 'org-export-icalendar
+  :type 'boolean
+  :package-version '(Org . "9.3")
+  :safe #'booleanp)
+
+(defcustom org-icalendar-warn-deadlines nil
+  "Non-nil means that a new VEVENT is created today to warn for deadlines.
+This only applies to TODOs that are not done.  Relies on
+`org-deadline-warning-days' for the number of days during which the warning
+is created."
+  :group 'org-export-icalendar
+  :type 'boolean
+  :package-version '(Org . "9.3")
+  :safe #'booleanp)
+
 (defcustom org-icalendar-categories '(local-tags category)
   "Items that should be entered into the \"categories\" field.
 
@@ -481,6 +499,28 @@ or subject for the event."
 	    (concat folded-line "\r\n " (substring line chunk-start))))))
     (org-split-string s "\n") "\r\n")))
 
+(defun org-icalendar-today-timestamp ()
+  "Return a TIMESTAMP object for today, at 00:00."
+  (let ((dt (decode-time)))
+    (list 'timestamp
+	  (nconc (list :year-start (nth 5 dt)
+                    :year-end (nth 5 dt)
+                    :month-start (nth 4 dt)
+                    :month-end (nth 4 dt)
+                    :day-start (nth 3 dt)
+                    :day-end (nth 3 dt))))))
+
+(defun org-icalendar-days-until-timestamp (timestamp)
+  "Return the number of days until TIMESTAMP.
+
+If TIMESTAMP occurs today, return 0.
+If TIMESTAMP occurs yesterday, return -1."
+  (floor
+   (/ (float-time
+       (time-subtract (org-timestamp-to-time timestamp)
+		      (apply 'encode-time
+			     (append '(0 0 0) (nthcdr 3 (decode-time))))))
+      (* 60 60 24))))
 
 \f
 ;;; Filters
@@ -567,19 +607,67 @@ inlinetask within the section."
 	  ;; "VEVENT" component from scheduled, deadline, or any
 	  ;; timestamp in the entry.
 	  (let ((deadline (org-element-property :deadline entry)))
-	    (and deadline
-		 (memq (if todo-type 'event-if-todo 'event-if-not-todo)
-		       org-icalendar-use-deadline)
-		 (org-icalendar--vevent
-		  entry deadline (concat "DL-" uid)
-		  (concat "DL: " summary) loc desc cat tz class)))
-	  (let ((scheduled (org-element-property :scheduled entry)))
-	    (and scheduled
-		 (memq (if todo-type 'event-if-todo 'event-if-not-todo)
-		       org-icalendar-use-scheduled)
-		 (org-icalendar--vevent
-		  entry scheduled (concat "SC-" uid)
-		  (concat "S: " summary) loc desc cat tz class)))
+	    (when (and deadline
+		       (memq (if todo-type 'event-if-todo 'event-if-not-todo)
+			     org-icalendar-use-deadline))
+	      (let ((days-until-deadline
+		     (org-icalendar-days-until-timestamp deadline)))
+		(cond
+		 ;; Case 1: Just export the event if...
+		 ((or
+		   ;; Not a pending TODO.
+		   (not (eq todo-type 'todo))
+		   ;; Is due today.
+		   (= days-until-deadline 0)
+		   ;; Overdue but no bumping.
+		   (and (not org-icalendar-bump-todos)
+			(< days-until-deadline 0))
+		   ;; In the future but no warning.
+		   (and (not org-icalendar-warn-deadlines)
+			(> days-until-deadline 0)))
+		  (org-icalendar--vevent
+		   entry deadline (concat "DL-" uid)
+		   (concat "DL: " summary) loc desc cat tz class))
+		 ;; Case 2: pending TODO overdue and should bump.
+		 ((and org-icalendar-bump-todos
+		       (< days-until-deadline 0))
+		  (org-icalendar--vevent
+		   entry (org-icalendar-today-timestamp) (concat "DL-" uid)
+		   (format "DL (%dx): %s" (- days-until-deadline) summary)
+		   loc desc cat tz class))
+		 ;; Case 3: in the future and should warn.
+		 (t
+		  (concat
+		   ;; If in the warning zone.
+		   (when (<= days-until-deadline org-deadline-warning-days)
+		     (org-icalendar--vevent
+		      entry (org-icalendar-today-timestamp)
+		      (format "DL-%s-%d" uid days-until-deadline)
+		      (format "DL (in %dd.): %s" days-until-deadline summary)
+		      loc desc cat tz class))
+		   (org-icalendar--vevent
+		    entry deadline (concat "DL-" uid)
+		    (concat "DL: " summary) loc desc cat tz class)))))))
+ 	  (let ((scheduled (org-element-property :scheduled entry)))
+	    (when (and scheduled
+		       (memq (if todo-type 'event-if-todo 'event-if-not-todo)
+			     org-icalendar-use-scheduled))
+	      (let ((days-until-scheduled
+		     (org-icalendar-days-until-timestamp scheduled)))
+		(cond
+		 ;; Already done, due in the future or today, or no bumps.
+		 ((or (not (eq todo-type 'todo))
+		      (>= days-until-scheduled 0)
+		      (not org-icalendar-bump-todos))
+		  (org-icalendar--vevent
+		   entry scheduled (concat "SC-" uid)
+		   (concat "S: " summary) loc desc cat tz class))
+		 ;; Overdue and should bump.
+		 (t
+		  (org-icalendar--vevent
+		   entry (org-icalendar-today-timestamp) (concat "SC-" uid)
+		   (format "S (%dx): %s" (- days-until-scheduled) summary)
+		   loc desc cat tz class))))))
 	  ;; When collecting plain timestamps from a headline and its
 	  ;; title, skip inlinetasks since collection will happen once
 	  ;; ENTRY is one of them.
-- 
2.22.0


  reply	other threads:[~2019-08-28 22:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 12:47 org-icalendar: Change dates to today in VEVENT export Michaël Cadilhac
2019-02-07 12:31 ` Michaël Cadilhac
2019-02-07 13:30   ` Nicolas Goaziou
2019-02-07 15:04     ` Michaël Cadilhac
2019-02-12  8:34       ` Nicolas Goaziou
2019-08-28 22:54         ` Michaël Cadilhac [this message]
2019-09-05 16:52           ` Nicolas Goaziou
2019-09-15 17:06             ` Michaël Cadilhac
2019-09-16 16:32               ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADt3fpNqAVDmCHkCSrYaTtpxqCFqQ_c8NNH35iiJJfbFYKuBnQ@mail.gmail.com \
    --to=michael@cadilhac.name \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).