comparison lisp/org/org-icalendar.el @ 111506:5cb272c831e8

Install org-mode version 7.3
author Carsten Dominik <carsten.dominik@gmail.com>
date Thu, 11 Nov 2010 22:10:19 -0600
parents a150e8a14679
children a7740098b594
comparison
equal deleted inserted replaced
111505:62aa3653746a 111506:5cb272c831e8
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Author: Carsten Dominik <carsten at orgmode dot org> 6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp 7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org 8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.01 9 ;; Version: 7.3
10 ;; 10 ;;
11 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
12 ;; 12 ;;
13 ;; GNU Emacs is free software: you can redistribute it and/or modify 13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by 14 ;; it under the terms of the GNU General Public License as published by
45 This file is created with the command \\[org-export-icalendar-all-agenda-files]. 45 This file is created with the command \\[org-export-icalendar-all-agenda-files].
46 The file name should be absolute, the file will be overwritten without warning." 46 The file name should be absolute, the file will be overwritten without warning."
47 :group 'org-export-icalendar 47 :group 'org-export-icalendar
48 :type 'file) 48 :type 'file)
49 49
50 (defcustom org-icalendar-alarm-time 0
51 "Number of minutes for triggering an alarm for exported timed events.
52 A zero value (the default) turns off the definition of an alarm trigger
53 for timed events. If non-zero, alarms are created.
54
55 - a single alarm per entry is defined
56 - The alarm will go off N minutes before the event
57 - only a DISPLAY action is defined."
58 :group 'org-export-icalendar
59 :type 'integer)
60
50 (defcustom org-icalendar-combined-name "OrgMode" 61 (defcustom org-icalendar-combined-name "OrgMode"
51 "Calendar name for the combined iCalendar representing all agenda files." 62 "Calendar name for the combined iCalendar representing all agenda files."
52 :group 'org-export-icalendar 63 :group 'org-export-icalendar
53 :type 'string) 64 :type 'string)
54 65
55 (defcustom org-icalendar-combined-description nil 66 (defcustom org-icalendar-combined-description nil
56 "Calendar description for the combined iCalendar representing all agenda files." 67 "Calendar description for the combined iCalendar (all agenda files)."
57 :group 'org-export-icalendar 68 :group 'org-export-icalendar
58 :type 'string) 69 :type 'string)
59 70
60 (defcustom org-icalendar-use-plain-timestamp t 71 (defcustom org-icalendar-use-plain-timestamp t
61 "Non-nil means make an event from every plain time stamp." 72 "Non-nil means make an event from every plain time stamp."
180 When nil of the empty string, use the abbreviation retrieved from Emacs." 191 When nil of the empty string, use the abbreviation retrieved from Emacs."
181 :group 'org-export-icalendar 192 :group 'org-export-icalendar
182 :type '(choice 193 :type '(choice
183 (const :tag "Unspecified" nil) 194 (const :tag "Unspecified" nil)
184 (string :tag "Time zone"))) 195 (string :tag "Time zone")))
196
197 (defcustom org-icalendar-use-UTC-date-time ()
198 "Non-nil force the use of the universal time for iCalendar DATE-TIME.
199 The iCalendar DATE-TIME can be expressed with local time or universal Time,
200 universal time could be more compatible with some external tools."
201 :group 'org-export-icalendar
202 :type 'boolean)
185 203
186 ;;; iCalendar export 204 ;;; iCalendar export
187 205
188 ;;;###autoload 206 ;;;###autoload
189 (defun org-export-icalendar-this-file () 207 (defun org-export-icalendar-this-file ()
280 (dts (org-ical-ts-to-string 298 (dts (org-ical-ts-to-string
281 (format-time-string (cdr org-time-stamp-formats) (current-time)) 299 (format-time-string (cdr org-time-stamp-formats) (current-time))
282 "DTSTART")) 300 "DTSTART"))
283 hd ts ts2 state status (inc t) pos b sexp rrule 301 hd ts ts2 state status (inc t) pos b sexp rrule
284 scheduledp deadlinep todo prefix due start 302 scheduledp deadlinep todo prefix due start
285 tmp pri categories location summary desc uid 303 tmp pri categories location summary desc uid alarm
286 (sexp-buffer (get-buffer-create "*ical-tmp*"))) 304 (sexp-buffer (get-buffer-create "*ical-tmp*")))
287 (org-refresh-category-properties) 305 (org-refresh-category-properties)
288 (save-excursion 306 (save-excursion
289 (goto-char (point-min)) 307 (goto-char (point-min))
290 (while (re-search-forward re1 nil t) 308 (while (re-search-forward re1 nil t)
298 (setq pos (match-beginning 0) 316 (setq pos (match-beginning 0)
299 ts (match-string 0) 317 ts (match-string 0)
300 inc t 318 inc t
301 hd (condition-case nil 319 hd (condition-case nil
302 (org-icalendar-cleanup-string 320 (org-icalendar-cleanup-string
303 (org-get-heading)) 321 (org-get-heading t))
304 (error (throw :skip nil))) 322 (error (throw :skip nil)))
305 summary (org-icalendar-cleanup-string 323 summary (org-icalendar-cleanup-string
306 (org-entry-get nil "SUMMARY")) 324 (org-entry-get nil "SUMMARY"))
307 desc (org-icalendar-cleanup-string 325 desc (org-icalendar-cleanup-string
308 (or (org-entry-get nil "DESCRIPTION") 326 (or (org-entry-get nil "DESCRIPTION")
312 (org-entry-get nil "LOCATION" 'selective)) 330 (org-entry-get nil "LOCATION" 'selective))
313 uid (if org-icalendar-store-UID 331 uid (if org-icalendar-store-UID
314 (org-id-get-create) 332 (org-id-get-create)
315 (or (org-id-get) (org-id-new))) 333 (or (org-id-get) (org-id-new)))
316 categories (org-export-get-categories) 334 categories (org-export-get-categories)
335 alarm ""
317 deadlinep nil scheduledp nil) 336 deadlinep nil scheduledp nil)
318 (if (looking-at re2) 337 (if (looking-at re2)
319 (progn 338 (progn
320 (goto-char (match-end 0)) 339 (goto-char (match-end 0))
321 (setq ts2 (match-string 1) 340 (setq ts2 (match-string 1)
360 '(("d" . "DAILY")("w" . "WEEKLY") 379 '(("d" . "DAILY")("w" . "WEEKLY")
361 ("m" . "MONTHLY")("y" . "YEARLY")))) 380 ("m" . "MONTHLY")("y" . "YEARLY"))))
362 ";INTERVAL=" (match-string 1 ts))) 381 ";INTERVAL=" (match-string 1 ts)))
363 (setq rrule "")) 382 (setq rrule ""))
364 (setq summary (or summary hd)) 383 (setq summary (or summary hd))
384 ;; create an alarm entry if the entry is timed. this is not very general in that:
385 ;; (a) only one alarm per entry is defined,
386 ;; (b) only minutes are allowed for the trigger period ahead of the start time, and
387 ;; (c) only a DISPLAY action is defined.
388 ;; [ESF]
389 (let ((t1 (ignore-errors (org-parse-time-string ts 'nodefault))))
390 (if (and (> org-icalendar-alarm-time 0)
391 (car t1) (nth 1 t1) (nth 2 t1))
392 (setq alarm (format "\nBEGIN:VALARM\nACTION:DISPLAY\nDESCRIPTION:%s\nTRIGGER:-P0D0H%dM0S\nEND:VALARM" summary org-icalendar-alarm-time))
393 (setq alarm ""))
394 )
365 (if (string-match org-bracket-link-regexp summary) 395 (if (string-match org-bracket-link-regexp summary)
366 (setq summary 396 (setq summary
367 (replace-match (if (match-end 3) 397 (replace-match (if (match-end 3)
368 (match-string 3 summary) 398 (match-string 3 summary)
369 (match-string 1 summary)) 399 (match-string 1 summary))
376 (princ (format "BEGIN:VEVENT 406 (princ (format "BEGIN:VEVENT
377 UID: %s 407 UID: %s
378 %s 408 %s
379 %s%s 409 %s%s
380 SUMMARY:%s%s%s 410 SUMMARY:%s%s%s
381 CATEGORIES:%s 411 CATEGORIES:%s%s
382 END:VEVENT\n" 412 END:VEVENT\n"
383 (concat prefix uid) 413 (concat prefix uid)
384 (org-ical-ts-to-string ts "DTSTART") 414 (org-ical-ts-to-string ts "DTSTART")
385 (org-ical-ts-to-string ts2 "DTEND" inc) 415 (org-ical-ts-to-string ts2 "DTEND" inc)
386 rrule summary 416 rrule summary
387 (if (and desc (string-match "\\S-" desc)) 417 (if (and desc (string-match "\\S-" desc))
388 (concat "\nDESCRIPTION: " desc) "") 418 (concat "\nDESCRIPTION: " desc) "")
389 (if (and location (string-match "\\S-" location)) 419 (if (and location (string-match "\\S-" location))
390 (concat "\nLOCATION: " location) "") 420 (concat "\nLOCATION: " location) "")
391 categories))))) 421 categories
422 alarm)))))
392 (when (and org-icalendar-include-sexps 423 (when (and org-icalendar-include-sexps
393 (condition-case nil (require 'icalendar) (error nil)) 424 (condition-case nil (require 'icalendar) (error nil))
394 (fboundp 'icalendar-export-region)) 425 (fboundp 'icalendar-export-region))
395 ;; Get all the literal sexps 426 ;; Get all the literal sexps
396 (goto-char (point-min)) 427 (goto-char (point-min))
413 (kill-buffer sexp-buffer)) 444 (kill-buffer sexp-buffer))
414 445
415 (when org-icalendar-include-todo 446 (when org-icalendar-include-todo
416 (setq prefix "TODO-") 447 (setq prefix "TODO-")
417 (goto-char (point-min)) 448 (goto-char (point-min))
418 (while (re-search-forward org-todo-line-regexp nil t) 449 (while (re-search-forward org-complex-heading-regexp nil t)
419 (catch :skip 450 (catch :skip
420 (org-agenda-skip) 451 (org-agenda-skip)
421 (when org-icalendar-verify-function 452 (when org-icalendar-verify-function
422 (unless (save-match-data 453 (unless (save-match-data
423 (funcall org-icalendar-verify-function)) 454 (funcall org-icalendar-verify-function))
445 :from 'todo 476 :from 'todo
446 :to 'done)))))) 477 :to 'done))))))
447 ((eq org-icalendar-include-todo t) 478 ((eq org-icalendar-include-todo t)
448 ;; include everything that is not done 479 ;; include everything that is not done
449 (member state org-not-done-keywords)))) 480 (member state org-not-done-keywords))))
450 (setq hd (match-string 3) 481 (setq hd (match-string 4)
451 summary (org-icalendar-cleanup-string 482 summary (org-icalendar-cleanup-string
452 (org-entry-get nil "SUMMARY")) 483 (org-entry-get nil "SUMMARY"))
453 desc (org-icalendar-cleanup-string 484 desc (org-icalendar-cleanup-string
454 (or (org-entry-get nil "DESCRIPTION") 485 (or (org-entry-get nil "DESCRIPTION")
455 (and org-icalendar-include-body (org-get-entry))) 486 (and org-icalendar-include-body (org-get-entry)))
608 (if org-agenda-default-appointment-duration 639 (if org-agenda-default-appointment-duration
609 (setq mi (+ org-agenda-default-appointment-duration mi)) 640 (setq mi (+ org-agenda-default-appointment-duration mi))
610 (setq h (+ 2 h))) 641 (setq h (+ 2 h)))
611 (setq d (1+ d)))) 642 (setq d (1+ d))))
612 (setq time (encode-time s mi h d m y))) 643 (setq time (encode-time s mi h d m y)))
613 (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d")) 644 (setq fmt (if have-time (if org-icalendar-use-UTC-date-time
614 (concat keyword (format-time-string fmt time))))) 645 ":%Y%m%dT%H%M%SZ"
646 ":%Y%m%dT%H%M%S")
647 ";VALUE=DATE:%Y%m%d"))
648 (concat keyword (format-time-string fmt time
649 (and org-icalendar-use-UTC-date-time
650 have-time))))))
615 651
616 (provide 'org-icalendar) 652 (provide 'org-icalendar)
617 653
618 ;; arch-tag: 2dee2b6e-9211-4aee-8a47-a3c7e5bc30cf 654 ;; arch-tag: 2dee2b6e-9211-4aee-8a47-a3c7e5bc30cf
619 ;;; org-icalendar.el ends here 655 ;;; org-icalendar.el ends here