]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-icalendar.el
Merge from emacs-24 branch
[gnu-emacs] / lisp / org / org-icalendar.el
index e0ea20a4bb8bf531a1bbb486774a6feb3d63bd53..d73a6195b321cac4bee91fbfad05206c6337e4e7 100644 (file)
@@ -1,11 +1,10 @@
 ;;; org-icalendar.el --- iCalendar export for Org-mode
 
-;; Copyright (C) 2004-201 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -55,6 +54,7 @@ for timed events.  If non-zero, alarms are created.
 - The alarm will go off N minutes before the event
 - only a DISPLAY action is defined."
   :group 'org-export-icalendar
+  :version "24.1"
   :type 'integer)
 
 (defcustom org-icalendar-combined-name "OrgMode"
@@ -65,6 +65,7 @@ for timed events.  If non-zero, alarms are created.
 (defcustom org-icalendar-combined-description nil
   "Calendar description for the combined iCalendar (all agenda files)."
   :group 'org-export-icalendar
+  :version "24.1"
   :type 'string)
 
 (defcustom org-icalendar-use-plain-timestamp t
@@ -72,6 +73,12 @@ for timed events.  If non-zero, alarms are created.
   :group 'org-export-icalendar
   :type 'boolean)
 
+(defcustom org-icalendar-honor-noexport-tag nil
+  "Non-nil means don't export entries with a tag in `org-export-exclude-tags'."
+  :group 'org-export-icalendar
+  :version "24.1"
+  :type 'boolean)
+
 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
   "Contexts where iCalendar export should use a deadline time stamp.
 This is a list with several symbols in it.  Valid symbol are:
@@ -193,12 +200,32 @@ When nil of the empty string, use the abbreviation retrieved from Emacs."
          (const :tag "Unspecified" nil)
          (string :tag "Time zone")))
 
-(defcustom org-icalendar-use-UTC-date-time ()
-  "Non-nil force the use of the universal time for iCalendar DATE-TIME.
-The iCalendar DATE-TIME can be expressed with local time or universal Time,
-universal time could be more compatible with some external tools."
+;; Backward compatibility with previous variable
+(defvar org-icalendar-use-UTC-date-time nil)
+(defcustom org-icalendar-date-time-format
+  (if org-icalendar-use-UTC-date-time
+      ":%Y%m%dT%H%M%SZ"
+    ":%Y%m%dT%H%M%S")
+  "Format-string for exporting icalendar DATE-TIME.
+See `format-time-string' for a full documentation.  The only
+difference is that `org-icalendar-timezone' is used for %Z.
+
+Interesting value are:
+ - \":%Y%m%dT%H%M%S\" for local time
+ - \";TZID=%Z:%Y%m%dT%H%M%S\" for local time with explicit timezone
+ - \":%Y%m%dT%H%M%SZ\" for time expressed in Universal Time"
+
   :group 'org-export-icalendar
-  :type 'boolean)
+  :version "24.1"
+  :type '(choice
+         (const :tag "Local time" ":%Y%m%dT%H%M%S")
+         (const :tag "Explicit local time" ";TZID=%Z:%Y%m%dT%H%M%S")
+         (const :tag "Universal time" ":%Y%m%dT%H%M%SZ")
+         (string :tag "Explicit format")))
+
+(defun org-icalendar-use-UTC-date-timep ()
+  (char-equal (elt org-icalendar-date-time-format
+                  (1- (length org-icalendar-date-time-format))) ?Z))
 
 ;;; iCalendar export
 
@@ -298,7 +325,7 @@ When COMBINE is non nil, add the category to each line."
              (format-time-string (cdr org-time-stamp-formats) (current-time))
              "DTSTART"))
        hd ts ts2 state status (inc t) pos b sexp rrule
-       scheduledp deadlinep todo prefix due start
+       scheduledp deadlinep todo prefix due start tags
        tmp pri categories location summary desc uid alarm
        (sexp-buffer (get-buffer-create "*ical-tmp*")))
     (org-refresh-category-properties)
@@ -314,6 +341,7 @@ When COMBINE is non nil, add the category to each line."
              (throw :skip nil)))
          (setq pos (match-beginning 0)
                ts (match-string 0)
+               tags (org-get-tags-at)
                inc t
                hd (condition-case nil
                       (org-icalendar-cleanup-string
@@ -354,6 +382,11 @@ When COMBINE is non nil, add the category to each line."
          (when (and (not org-icalendar-use-plain-timestamp)
                     (not deadlinep) (not scheduledp))
            (throw :skip t))
+         ;; don't export entries with a :noexport: tag
+         (when (and org-icalendar-honor-noexport-tag
+                    (delq nil (mapcar (lambda(x)
+                                        (member x org-export-exclude-tags)) tags)))
+           (throw :skip t))
          (when (and
                 deadlinep
                 (if todo
@@ -386,9 +419,9 @@ When COMBINE is non nil, add the category to each line."
          ;; (c) only a DISPLAY action is defined.
          ;; [ESF]
          (let ((t1 (ignore-errors (org-parse-time-string ts 'nodefault))))
-           (if (and (> org-icalendar-alarm-time 0) 
+           (if (and (> org-icalendar-alarm-time 0)
                     (car t1) (nth 1 t1) (nth 2 t1))
-               (setq alarm (format "\nBEGIN:VALARM\nACTION:DISPLAY\nDESCRIPTION:%s\nTRIGGER:-P0D0H%dM0S\nEND:VALARM" summary org-icalendar-alarm-time))
+               (setq alarm (format "\nBEGIN:VALARM\nACTION:DISPLAY\nDESCRIPTION:%s\nTRIGGER:-P0DT0H%dM0S\nEND:VALARM" summary org-icalendar-alarm-time))
              (setq alarm ""))
            )
          (if (string-match org-bracket-link-regexp summary)
@@ -401,7 +434,10 @@ When COMBINE is non nil, add the category to each line."
          (if scheduledp (setq summary (concat "S: " summary)))
          (if (string-match "\\`<%%" ts)
              (with-current-buffer sexp-buffer
-               (insert (substring ts 1 -1) " " summary "\n"))
+               (let ((entry (substring ts 1 -1)))
+                 (put-text-property 0 1 'uid
+                                    (concat " " prefix uid) entry)
+                 (insert entry " " summary "\n")))
            (princ (format "BEGIN:VEVENT
 UID: %s
 %s
@@ -640,12 +676,13 @@ a time), or the day by one (if it does not contain a time)."
                (setq h (+ 2 h)))
            (setq d (1+ d))))
        (setq time (encode-time s mi h d m y)))
-      (setq fmt (if have-time (if org-icalendar-use-UTC-date-time 
-                                 ":%Y%m%dT%H%M%SZ"
-                                 ":%Y%m%dT%H%M%S")
+      (setq fmt (if have-time
+                   (replace-regexp-in-string "%Z"
+                                             org-icalendar-timezone
+                                             org-icalendar-date-time-format)
                    ";VALUE=DATE:%Y%m%d"))
-      (concat keyword (format-time-string fmt time 
-                                         (and org-icalendar-use-UTC-date-time 
+      (concat keyword (format-time-string fmt time
+                                         (and (org-icalendar-use-UTC-date-timep)
                                               have-time))))))
 
 (provide 'org-icalendar)