From a7ae9951fa515dc9e3e3a43753ec54a47ad81f27 Mon Sep 17 00:00:00 2001 From: plantarum Date: Mon, 25 Jan 2021 20:59:51 -0500 Subject: [PATCH 1/3] Documented icalendar capture templates It's not documented in gnus-icalendar, so the explanation comes straight from my reading of the code. --- mu4e/mu4e.texi | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 464557c6..5856be9e 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -3414,6 +3414,34 @@ To enable optional iCalendar→Org sync functionality, add the following: Both the capture file and the headline(s) inside it must already exist. +By default, @code{gnus-icalendar-org-setup} adds a temporary capture +template to the variable @code{org-capture-templates}, with the +description ``used by gnus-icalendar-org'', and the shortcut key ``#''. +If you want to use your own template, create it using the same key +and description. This will prevent the temporary one from being +installed next time you @code{gnus-icalendar-org-setup} is called. + +The full default capture template is: + +@lisp +("#" "used by gnus-icalendar-org" entry + (file+olp ,gnus-icalendar-org-capture-file ,gnus-icalendar-org-capture-headline) + "%i" :immediate-finish t) +@end lisp + +where the values of the variables @code{gnus-icalendar-org-capture-file} +and @code{gnus-icalendar-org-capture-headline} are inserted via macro +expansion. + +If, for example, you wanted to store ical events in a date tree, +prompting for the date, you could use the following: + +@lisp +("#" "used by gnus-icalendar-org" entry + (file+olp+datetree path-to-capture-file) + "%i" :immediate-finish t :time-prompt t) +@end lisp + @node Sauron @section Sauron From 51f0a6b73945cc5a7e55cf36441ee52bd576350c Mon Sep 17 00:00:00 2001 From: plantarum Date: Tue, 26 Jan 2021 10:46:21 -0500 Subject: [PATCH 2/3] Added doc for automatically setting the datetree location Advice appears to be the cleanest way to do this. --- mu4e/mu4e.texi | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 5856be9e..c83a06b4 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -3425,7 +3425,8 @@ The full default capture template is: @lisp ("#" "used by gnus-icalendar-org" entry - (file+olp ,gnus-icalendar-org-capture-file ,gnus-icalendar-org-capture-headline) + (file+olp ,gnus-icalendar-org-capture-file + ,gnus-icalendar-org-capture-headline) "%i" :immediate-finish t) @end lisp @@ -3442,6 +3443,26 @@ prompting for the date, you could use the following: "%i" :immediate-finish t :time-prompt t) @end lisp +Note that the default behaviour for @code{datetree} targets in this situation +is to store the event at the date that you capture it, not at the date +that it is scheduled. That's why I've suggested using the +@code{:timeprompt t} argument. This gives you an opportunity to set the +time to the correct value yourself. + +You can extract the event time directly, and have the @code{org-capture} +functions use that to set the @code{datetree} location: + +@lisp +(defun my-catch-event-time (event reply-status) + "Set org-overriding-default-time to the start time of the capture event" + (setq org-overriding-default-time + (date-to-time (gnus-icalendar-event:start event)))) + +(advice-add 'gnus-icalendar:org-event-save :before #'my-catch-event-time) +@end lisp + +If you do this, you'll want to omit the @code{:timeprompt t} setting +from your capture template. @node Sauron @section Sauron From a440510cdd77b00202da63c5870ab186cedd70ab Mon Sep 17 00:00:00 2001 From: plantarum Date: Tue, 26 Jan 2021 13:52:43 -0500 Subject: [PATCH 3/3] changed from before/setq to around/let to limit scope let is better than setq, as it doesn't permanently alter the value of org-overriding-default-time. The setq has knock-on impacts in future captures that use the value of this variable, if it is set. --- mu4e/mu4e.texi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index c83a06b4..635b67bd 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -3453,12 +3453,13 @@ You can extract the event time directly, and have the @code{org-capture} functions use that to set the @code{datetree} location: @lisp -(defun my-catch-event-time (event reply-status) +(defun my-catch-event-time (orig-fun &rest args) "Set org-overriding-default-time to the start time of the capture event" - (setq org-overriding-default-time - (date-to-time (gnus-icalendar-event:start event)))) + (let ((org-overriding-default-time (date-to-time + (gnus-icalendar-event:start (car args))))) + (apply orig-fun args))) -(advice-add 'gnus-icalendar:org-event-save :before #'my-catch-event-time) +(advice-add 'gnus-icalendar:org-event-save :around #'my-catch-event-time) @end lisp If you do this, you'll want to omit the @code{:timeprompt t} setting