annotate lisp/calendar/icalendar.el @ 82916:b63eed64a25b

(x_draw_composite_glyph_string_foreground): Draw rectangle for nonexistent or zero-width glyph in composition glyph.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Mon, 27 Aug 2007 08:31:07 +0000
parents 93e11478c954
children 974a828870fe 527b0ddd39b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1 ;;; icalendar.el --- iCalendar implementation -*-coding: utf-8 -*-
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
75346
7a3f13e2dd57 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 75141
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
5 ;; Author: Ulf Jasper <ulf.jasper@web.de>
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
6 ;; Created: August 2002
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
7 ;; Keywords: calendar
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 ;; Human-Keywords: calendar, diary, iCalendar, vCalendar
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
78216
93e11478c954 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 77934
diff changeset
14 ;; the Free Software Foundation; either version 3, or (at your option)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 ;; any later version.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62902
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62902
diff changeset
25 ;; Boston, MA 02110-1301, USA.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;; This package is documented in the Emacs Manual.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
31 ;; Please note:
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
32 ;; - Diary entries which have a start time but no end time are assumed to
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
33 ;; last for one hour when they are exported.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
34 ;; - Weekly diary entries are assumed to occur the first time in the first
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
35 ;; week of the year 2000 when they are exported.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
36 ;; - Yearly diary entries are assumed to occur the first time in the year
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
37 ;; 1900 when they are exported.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 ;;; History:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
41 ;; 0.07 onwards: see lisp/ChangeLog
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
42
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
43 ;; 0.06: Bugfixes regarding icalendar-import-format-*.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
44 ;; Fix in icalendar-convert-diary-to-ical -- thanks to Philipp
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
45 ;; Grau.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ;; 0.05: New import format scheme: Replaced icalendar-import-prefix-*,
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ;; icalendar-import-ignored-properties, and
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 ;; icalendar-import-separator with icalendar-import-format(-*).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ;; icalendar-import-file and icalendar-convert-diary-to-ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 ;; have an extra parameter which should prevent them from
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 ;; erasing their target files (untested!).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 ;; Tested with Emacs 21.3.2
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 ;; 0.04: Bugfix: import: double quoted param values did not work
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 ;; Read DURATION property when importing.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 ;; Added parameter icalendar-duration-correction.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 ;; 0.03: Export takes care of european-calendar-style.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 ;; Tested with Emacs 21.3.2 and XEmacs 21.4.12
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 ;; 0.02: Should work in XEmacs now. Thanks to Len Trigg for the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 ;; XEmacs patches!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 ;; Added exporting from Emacs diary to ical.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 ;; Some bugfixes, after testing with calendars from
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 ;; http://icalshare.com.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 ;; Tested with Emacs 21.3.2 and XEmacs 21.4.12
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 ;; 0.01: First published version. Trial version. Alpha version.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 ;; To Do:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
74 ;; * Import from ical to diary:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 ;; + Need more properties for icalendar-import-format
74673
9963f42a0a19 From Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 68943
diff changeset
76 ;; (added all that Mozilla Calendar uses)
9963f42a0a19 From Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 68943
diff changeset
77 ;; From iCal specifications (RFC2445: 4.8.1), icalendar.el lacks
9963f42a0a19 From Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 68943
diff changeset
78 ;; ATTACH, CATEGORIES, COMMENT, GEO, PERCENT-COMPLETE (VTODO),
9963f42a0a19 From Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 68943
diff changeset
79 ;; PRIORITY, RESOURCES) not considering date/time and time-zone
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 ;; + check vcalendar version
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 ;; + check (unknown) elements
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 ;; + recurring events!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 ;; + works for european style calendars only! Does it?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 ;; + alarm
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 ;; + exceptions in recurring events
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 ;; + the parser is too soft
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 ;; + error log is incomplete
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 ;; + nice to have: #include "webcal://foo.com/some-calendar.ics"
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
89 ;; + timezones, currently all times are local!
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
91 ;; * Export from diary to ical
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 ;; + diary-date, diary-float, and self-made sexp entries are not
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 ;; understood
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 ;; * Other things
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 ;; + clean up all those date/time parsing functions
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 ;; + Handle todo items?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 ;; + Check iso 8601 for datetime and period
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 ;; + Which chars to (un)escape?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 ;;; Code:
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
104 (defconst icalendar-version "0.15"
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 "Version number of icalendar.el.")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 ;; Customizables
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 (defgroup icalendar nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 "Icalendar support."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 :prefix "icalendar-"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 :group 'calendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 (defcustom icalendar-import-format
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 "%s%d%l%o"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 "Format string for importing events from iCalendar into Emacs diary.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 This string defines how iCalendar events are inserted into diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 file. Meaning of the specifiers:
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
120 %c Class, see `icalendar-import-format-class'
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 %d Description, see `icalendar-import-format-description'
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 %l Location, see `icalendar-import-format-location'
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 %o Organizer, see `icalendar-import-format-organizer'
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
124 %s Summary, see `icalendar-import-format-summary'
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
125 %t Status, see `icalendar-import-format-status'
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
126 %u URL, see `icalendar-import-format-url'"
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
130 (defcustom icalendar-import-format-summary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 "%s"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
132 "Format string defining how the summary element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
133 This applies only if the summary is not empty! `%s' is replaced
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
134 by the summary."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 (defcustom icalendar-import-format-description
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 "\n Desc: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 "Format string defining how the description element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 This applies only if the description is not empty! `%s' is
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 replaced by the description."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 (defcustom icalendar-import-format-location
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 "\n Location: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 "Format string defining how the location element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 This applies only if the location is not empty! `%s' is replaced
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 by the location."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 (defcustom icalendar-import-format-organizer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 "\n Organizer: %s"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 "Format string defining how the organizer element is formatted.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 This applies only if the organizer is not empty! `%s' is
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 replaced by the organizer."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 :type 'string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 :group 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
162 (defcustom icalendar-import-format-url
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
163 "\n URL: %s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
164 "Format string defining how the URL element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
165 This applies only if the URL is not empty! `%s' is replaced by
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
166 the URL."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
167 :type 'string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
168 :group 'icalendar)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
169
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
170 (defcustom icalendar-import-format-status
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
171 "\n Status: %s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
172 "Format string defining how the status element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
173 This applies only if the status is not empty! `%s' is replaced by
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
174 the status."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
175 :type 'string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
176 :group 'icalendar)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
177
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
178 (defcustom icalendar-import-format-class
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
179 "\n Class: %s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
180 "Format string defining how the class element is formatted.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
181 This applies only if the class is not empty! `%s' is replaced by
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
182 the class."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
183 :type 'string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
184 :group 'icalendar)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
185
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
186 (defvar icalendar-debug nil
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
187 "Enable icalendar debug messages.")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 ;; NO USER SERVICABLE PARTS BELOW THIS LINE
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
193 (defconst icalendar--weekday-array ["SU" "MO" "TU" "WE" "TH" "FR" "SA"])
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 ;; all the other libs we need
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 (require 'calendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
201 ;; misc
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
202 ;; ======================================================================
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
203 (defun icalendar--dmsg (&rest args)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
204 "Print message ARGS if `icalendar-debug' is non-nil."
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
205 (if icalendar-debug
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
206 (apply 'message args)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
207
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
208 ;; ======================================================================
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 ;; Core functionality
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 ;; Functions for parsing icalendars, importing and so on
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
213 (defun icalendar--get-unfolded-buffer (folded-ical-buffer)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 "Return a new buffer containing the unfolded contents of a buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 Folding is the iCalendar way of wrapping long lines. In the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 created buffer all occurrences of CR LF BLANK are replaced by the
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 empty string. Argument FOLDED-ICAL-BUFFER is the unfolded input
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 buffer."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (let ((unfolded-buffer (get-buffer-create " *icalendar-work*")))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 (set-buffer unfolded-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 (erase-buffer)
64432
cd3c7f95237e (icalendar--get-unfolded-buffer): Use `insert-buffer-substring' and `goto-char',
Juanma Barranquero <lekktu@gmail.com>
parents: 64085
diff changeset
223 (insert-buffer-substring folded-ical-buffer)
cd3c7f95237e (icalendar--get-unfolded-buffer): Use `insert-buffer-substring' and `goto-char',
Juanma Barranquero <lekktu@gmail.com>
parents: 64085
diff changeset
224 (goto-char (point-min))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 (while (re-search-forward "\r?\n[ \t]" nil t)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
226 (replace-match "" nil nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 unfolded-buffer))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
229 (defsubst icalendar--rris (regexp rep string &optional fixedcase literal)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
230 "Replace regular expression in string.
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
231 Pass arguments REGEXP REP STRING FIXEDCASE LITERAL to
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
232 `replace-regexp-in-string' (Emacs) or to `replace-in-string' (XEmacs)."
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
233 (cond ((fboundp 'replace-regexp-in-string)
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
234 ;; Emacs:
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
235 (replace-regexp-in-string regexp rep string fixedcase literal))
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
236 ((fboundp 'replace-in-string)
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
237 ;; XEmacs:
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
238 (save-match-data ;; apparently XEmacs needs save-match-data
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
239 (replace-in-string string regexp rep literal)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
241 (defun icalendar--read-element (invalue inparams)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242 "Recursively read the next iCalendar element in the current buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
243 INVALUE gives the current iCalendar element we are reading.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244 INPARAMS gives the current parameters.....
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 This function calls itself recursively for each nested calendar element
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 it finds"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 (let (element children line name params param param-name param-value
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
248 value
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
249 (continue t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250 (setq children '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 (while (and continue
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 (re-search-forward "^\\([A-Za-z0-9-]+\\)[;:]" nil t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253 (setq name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254 (backward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 (setq params '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 (setq line '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 (while (looking-at ";")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 (re-search-forward ";\\([A-Za-z0-9-]+\\)=" nil nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 (setq param-name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260 (re-search-forward "\\(\\([^;,:\"]+\\)\\|\"\\([^\"]+\\)\"\\)[;:]"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 (backward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 (setq param-value (or (match-string 2) (match-string 3)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 (setq param (list param-name param-value))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265 (while (looking-at ",")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 (re-search-forward "\\(\\([^;,:]+\\)\\|\"\\([^\"]+\\)\"\\)"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
267 nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268 (if (match-string 2)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269 (setq param-value (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 (setq param-value (match-string 3)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 (setq param (append param param-value)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
272 (setq params (append params param)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
273 (unless (looking-at ":")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
274 (error "Oops"))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
275 (forward-char 1)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
276 (re-search-forward "\\(.*\\)\\(\r?\n[ \t].*\\)*" nil t)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
277 (setq value (icalendar--rris "\r?\n[ \t]" "" (match-string 0)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
278 (setq line (list name params value))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
279 (cond ((eq name 'BEGIN)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
280 (setq children
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
281 (append children
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
282 (list (icalendar--read-element (intern value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
283 params)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
284 ((eq name 'END)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
285 (setq continue nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
286 (t
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
287 (setq element (append element (list line))))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
288 (if invalue
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
289 (list invalue inparams element children)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
290 children)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
291
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
292 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
293 ;; helper functions for examining events
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
294 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
295
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
296 ;;(defsubst icalendar--get-all-event-properties (event)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
297 ;; "Return the list of properties in this EVENT."
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
298 ;; (car (cddr event)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
299
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
300 (defun icalendar--get-event-property (event prop)
68930
16194e6e2a7b (icalendar--get-event-property, icalendar--get-event-property-attributes):
Juanma Barranquero <lekktu@gmail.com>
parents: 68721
diff changeset
301 "For the given EVENT return the value of the first occurrence of PROP."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
302 (catch 'found
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
303 (let ((props (car (cddr event))) pp)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
304 (while props
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
305 (setq pp (car props))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
306 (if (eq (car pp) prop)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
307 (throw 'found (car (cddr pp))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
308 (setq props (cdr props))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
309 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
310
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
311 (defun icalendar--get-event-property-attributes (event prop)
68930
16194e6e2a7b (icalendar--get-event-property, icalendar--get-event-property-attributes):
Juanma Barranquero <lekktu@gmail.com>
parents: 68721
diff changeset
312 "For the given EVENT return attributes of the first occurrence of PROP."
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
313 (catch 'found
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
314 (let ((props (car (cddr event))) pp)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
315 (while props
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
316 (setq pp (car props))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
317 (if (eq (car pp) prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
318 (throw 'found (cadr pp)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
319 (setq props (cdr props))))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
320 nil))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
321
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
322 (defun icalendar--get-event-properties (event prop)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
323 "For the given EVENT return a list of all values of the property PROP."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
324 (let ((props (car (cddr event))) pp result)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
325 (while props
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
326 (setq pp (car props))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
327 (if (eq (car pp) prop)
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
328 (setq result (append (split-string (car (cddr pp)) ",") result)))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
329 (setq props (cdr props)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
330 result))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
331
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
332 ;; (defun icalendar--set-event-property (event prop new-value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
333 ;; "For the given EVENT set the property PROP to the value NEW-VALUE."
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
334 ;; (catch 'found
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
335 ;; (let ((props (car (cddr event))) pp)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
336 ;; (while props
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
337 ;; (setq pp (car props))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
338 ;; (when (eq (car pp) prop)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
339 ;; (setcdr (cdr pp) new-value)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
340 ;; (throw 'found (car (cddr pp))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
341 ;; (setq props (cdr props)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
342 ;; (setq props (car (cddr event)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
343 ;; (setcar (cddr event)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
344 ;; (append props (list (list prop nil new-value)))))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
345
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
346 (defun icalendar--get-children (node name)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
347 "Return all children of the given NODE which have a name NAME.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
348 For instance the VCALENDAR node can have VEVENT children as well as VTODO
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
349 children."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
350 (let ((result nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
351 (children (cadr (cddr node))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
352 (when (eq (car node) name)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
353 (setq result node))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
354 ;;(message "%s" node)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
355 (when children
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
356 (let ((subresult
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
357 (delq nil
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
358 (mapcar (lambda (n)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
359 (icalendar--get-children n name))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
360 children))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
361 (if subresult
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
362 (if result
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
363 (setq result (append result subresult))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
364 (setq result subresult)))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
365 result))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
366
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
367 ; private
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
368 (defun icalendar--all-events (icalendar)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
369 "Return the list of all existing events in the given ICALENDAR."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
370 (icalendar--get-children (car icalendar) 'VEVENT))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
371
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
372 (defun icalendar--split-value (value-string)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
373 "Split VALUE-STRING at ';='."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
374 (let ((result '())
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
375 param-name param-value)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
376 (when value-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
377 (save-current-buffer
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
378 (set-buffer (get-buffer-create " *icalendar-work*"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
379 (set-buffer-modified-p nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
380 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
381 (insert value-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
382 (goto-char (point-min))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
383 (while
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
384 (re-search-forward
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
385 "\\([A-Za-z0-9-]+\\)=\\(\\([^;,:]+\\)\\|\"\\([^\"]+\\)\"\\);?"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
386 nil t)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
387 (setq param-name (intern (match-string 1)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
388 (setq param-value (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
389 (setq result
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
390 (append result (list (list param-name param-value)))))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
391 result))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
392
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
393 (defun icalendar--decode-isodatetime (isodatetimestring &optional day-shift)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
394 "Return ISODATETIMESTRING in format like `decode-time'.
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
395 Converts from ISO-8601 to Emacs representation. If
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
396 ISODATETIMESTRING specifies UTC time (trailing letter Z) the
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
397 decoded time is given in the local time zone! If optional
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
398 parameter DAY-SHIFT is non-nil the result is shifted by DAY-SHIFT
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
399 days.
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
400
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
401 FIXME: TZID-attributes are ignored....!
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
402 FIXME: multiple comma-separated values should be allowed!"
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
403 (icalendar--dmsg isodatetimestring)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
404 (if isodatetimestring
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
405 ;; day/month/year must be present
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
406 (let ((year (read (substring isodatetimestring 0 4)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
407 (month (read (substring isodatetimestring 4 6)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
408 (day (read (substring isodatetimestring 6 8)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
409 (hour 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
410 (minute 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
411 (second 0))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
412 (when (> (length isodatetimestring) 12)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
413 ;; hour/minute present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
414 (setq hour (read (substring isodatetimestring 9 11)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
415 (setq minute (read (substring isodatetimestring 11 13))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
416 (when (> (length isodatetimestring) 14)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
417 ;; seconds present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
418 (setq second (read (substring isodatetimestring 13 15))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
419 (when (and (> (length isodatetimestring) 15)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
420 ;; UTC specifier present
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
421 (char-equal ?Z (aref isodatetimestring 15)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
422 ;; if not UTC add current-time-zone offset
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
423 (setq second (+ (car (current-time-zone)) second)))
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
424 ;; shift if necessary
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
425 (if day-shift
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
426 (let ((mdy (calendar-gregorian-from-absolute
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
427 (+ (calendar-absolute-from-gregorian
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
428 (list month day year))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
429 day-shift))))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
430 (setq month (nth 0 mdy))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
431 (setq day (nth 1 mdy))
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
432 (setq year (nth 2 mdy))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
433 ;; create the decoded date-time
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
434 ;; FIXME!?!
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
435 (condition-case nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
436 (decode-time (encode-time second minute hour day month year))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
437 (error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
438 (message "Cannot decode \"%s\"" isodatetimestring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
439 ;; hope for the best...
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
440 (list second minute hour day month year 0 nil 0))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
441 ;; isodatetimestring == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
442 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
443
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
444 (defun icalendar--decode-isoduration (isodurationstring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
445 &optional duration-correction)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
446 "Convert ISODURATIONSTRING into format provided by `decode-time'.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
447 Converts from ISO-8601 to Emacs representation. If ISODURATIONSTRING
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
448 specifies UTC time (trailing letter Z) the decoded time is given in
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
449 the local time zone!
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
450
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
451 Optional argument DURATION-CORRECTION shortens result by one day.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
452
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
453 FIXME: TZID-attributes are ignored....!
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
454 FIXME: multiple comma-separated values should be allowed!"
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
455 (if isodurationstring
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
456 (save-match-data
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
457 (string-match
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
458 (concat
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
459 "^P[+-]?\\("
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
460 "\\(\\([0-9]+\\)D\\)" ; days only
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
461 "\\|"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
462 "\\(\\(\\([0-9]+\\)D\\)?T\\(\\([0-9]+\\)H\\)?" ; opt days
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
463 "\\(\\([0-9]+\\)M\\)?\\(\\([0-9]+\\)S\\)?\\)" ; mand. time
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
464 "\\|"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
465 "\\(\\([0-9]+\\)W\\)" ; weeks only
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
466 "\\)$") isodurationstring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
467 (let ((seconds 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
468 (minutes 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
469 (hours 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
470 (days 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
471 (months 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
472 (years 0))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
473 (cond
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
474 ((match-beginning 2) ;days only
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
475 (setq days (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
476 (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
477 (match-end 3))))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
478 (when duration-correction
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
479 (setq days (1- days))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
480 ((match-beginning 4) ;days and time
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
481 (if (match-beginning 5)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
482 (setq days (* 7 (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
483 (match-beginning 6)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
484 (match-end 6))))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
485 (if (match-beginning 7)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
486 (setq hours (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
487 (match-beginning 8)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
488 (match-end 8)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
489 (if (match-beginning 9)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
490 (setq minutes (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
491 (match-beginning 10)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
492 (match-end 10)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
493 (if (match-beginning 11)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
494 (setq seconds (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
495 (match-beginning 12)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
496 (match-end 12))))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
497 ((match-beginning 13) ;weeks only
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
498 (setq days (* 7 (read (substring isodurationstring
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
499 (match-beginning 14)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
500 (match-end 14)))))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
501 (list seconds minutes hours days months years)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
502 ;; isodatetimestring == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
503 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
504
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
505 (defun icalendar--add-decoded-times (time1 time2)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
506 "Add TIME1 to TIME2.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
507 Both times must be given in decoded form. One of these times must be
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
508 valid (year > 1900 or something)."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
509 ;; FIXME: does this function exist already?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
510 (decode-time (encode-time
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
511 (+ (nth 0 time1) (nth 0 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
512 (+ (nth 1 time1) (nth 1 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
513 (+ (nth 2 time1) (nth 2 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
514 (+ (nth 3 time1) (nth 3 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
515 (+ (nth 4 time1) (nth 4 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
516 (+ (nth 5 time1) (nth 5 time2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
517 nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
518 nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
519 ;;(or (nth 6 time1) (nth 6 time2)) ;; FIXME?
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
520 )))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
521
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
522 (defun icalendar--datetime-to-noneuropean-date (datetime &optional separator)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
523 "Convert the decoded DATETIME to non-european-style format.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
524 Optional argument SEPARATOR gives the separator between month,
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
525 day, and year. If nil a blank character is used as separator.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
526 Non-European format: \"month day year\"."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
527 (if datetime
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
528 (format "%d%s%d%s%d" (nth 4 datetime) ;month
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
529 (or separator " ")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
530 (nth 3 datetime) ;day
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
531 (or separator " ")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
532 (nth 5 datetime)) ;year
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
533 ;; datetime == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
534 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
535
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
536 (defun icalendar--datetime-to-european-date (datetime &optional separator)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
537 "Convert the decoded DATETIME to European format.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
538 Optional argument SEPARATOR gives the separator between month,
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
539 day, and year. If nil a blank character is used as separator.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
540 European format: (day month year).
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
541 FIXME"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
542 (if datetime
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
543 (format "%d%s%d%s%d" (nth 3 datetime) ;day
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
544 (or separator " ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
545 (nth 4 datetime) ;month
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
546 (or separator " ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
547 (nth 5 datetime)) ;year
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
548 ;; datetime == nil
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
549 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
550
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
551 (defun icalendar--datetime-to-diary-date (datetime &optional separator)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
552 "Convert the decoded DATETIME to diary format.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
553 Optional argument SEPARATOR gives the separator between month,
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
554 day, and year. If nil a blank character is used as separator.
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
555 Call icalendar--datetime-to-(non)-european-date according to
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
556 value of `european-calendar-style'."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
557 (if european-calendar-style
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
558 (icalendar--datetime-to-european-date datetime separator)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
559 (icalendar--datetime-to-noneuropean-date datetime separator)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
560
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
561 (defun icalendar--datetime-to-colontime (datetime)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
562 "Extract the time part of a decoded DATETIME into 24-hour format.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
563 Note that this silently ignores seconds."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
564 (format "%02d:%02d" (nth 2 datetime) (nth 1 datetime)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
565
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
566 (defun icalendar--get-month-number (monthname)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
567 "Return the month number for the given MONTHNAME."
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
568 (catch 'found
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
569 (let ((num 1)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
570 (m (downcase monthname)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
571 (mapc (lambda (month)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
572 (let ((mm (downcase month)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
573 (if (or (string-equal mm m)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
574 (string-equal (substring mm 0 3) m))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
575 (throw 'found num))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
576 (setq num (1+ num))))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
577 calendar-month-name-array))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
578 ;; Error:
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
579 -1))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
580
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
581 (defun icalendar--get-weekday-number (abbrevweekday)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
582 "Return the number for the ABBREVWEEKDAY."
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
583 (if abbrevweekday
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
584 (catch 'found
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
585 (let ((num 0)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
586 (aw (downcase abbrevweekday)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
587 (mapc (lambda (day)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
588 (let ((d (downcase day)))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
589 (if (string-equal d aw)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
590 (throw 'found num))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
591 (setq num (1+ num))))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
592 icalendar--weekday-array)))
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
593 ;; Error:
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
594 -1))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
595
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
596 (defun icalendar--get-weekday-abbrev (weekday)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
597 "Return the abbreviated WEEKDAY."
57652
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
598 (catch 'found
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
599 (let ((num 0)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
600 (w (downcase weekday)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
601 (mapc (lambda (day)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
602 (let ((d (downcase day)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
603 (if (or (string-equal d w)
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
604 (string-equal (substring d 0 3) w))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
605 (throw 'found (aref icalendar--weekday-array num)))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
606 (setq num (1+ num))))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
607 calendar-day-name-array))
1d0ad14ff912 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57586
diff changeset
608 ;; Error:
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
609 nil))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
610
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
611 (defun icalendar--date-to-isodate (date &optional day-shift)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
612 "Convert DATE to iso-style date.
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
613 DATE must be a list of the form (month day year).
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
614 If DAY-SHIFT is non-nil, the result is shifted by DAY-SHIFT days."
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
615 (let ((mdy (calendar-gregorian-from-absolute
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
616 (+ (calendar-absolute-from-gregorian date)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
617 (or day-shift 0)))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
618 (format "%04d%02d%02d" (nth 2 mdy) (nth 0 mdy) (nth 1 mdy))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
619
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
620
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
621 (defun icalendar--datestring-to-isodate (datestring &optional day-shift)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
622 "Convert diary-style DATESTRING to iso-style date.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
623 If DAY-SHIFT is non-nil, the result is shifted by DAY-SHIFT days
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
624 -- DAY-SHIFT must be either nil or an integer. This function
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
625 takes care of european-style."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
626 (let ((day -1) month year)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
627 (save-match-data
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
628 (cond ( ;; numeric date
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
629 (string-match (concat "\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
630 "0?\\([1-9][0-9]?\\)[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
631 "0?\\([1-9][0-9]?\\),?[ \t/]\\s-*"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
632 "\\([0-9]\\{4\\}\\)")
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
633 datestring)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
634 (setq day (read (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
635 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
636 (setq month (read (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
637 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
638 (setq year (read (substring datestring (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
639 (match-end 3))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
640 (unless european-calendar-style
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
641 (let ((x month))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
642 (setq month day)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
643 (setq day x))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
644 ( ;; date contains month names -- european-style
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
645 (string-match (concat "\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
646 "0?\\([123]?[0-9]\\)[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
647 "\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
648 "\\([0-9]\\{4\\}\\)")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
649 datestring)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
650 (setq day (read (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
651 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
652 (setq month (icalendar--get-month-number
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
653 (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
654 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
655 (setq year (read (substring datestring (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
656 (match-end 3)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
657 ( ;; date contains month names -- non-european-style
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
658 (string-match (concat "\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
659 "\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
660 "0?\\([123]?[0-9]\\),?[ \t/]\\s-*"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
661 "\\([0-9]\\{4\\}\\)")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
662 datestring)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
663 (setq day (read (substring datestring (match-beginning 2)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
664 (match-end 2))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
665 (setq month (icalendar--get-month-number
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
666 (substring datestring (match-beginning 1)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
667 (match-end 1))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
668 (setq year (read (substring datestring (match-beginning 3)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
669 (match-end 3)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
670 (t
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
671 nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
672 (if (> day 0)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
673 (let ((mdy (calendar-gregorian-from-absolute
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
674 (+ (calendar-absolute-from-gregorian (list month day
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
675 year))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
676 (or day-shift 0)))))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
677 (format "%04d%02d%02d" (nth 2 mdy) (nth 0 mdy) (nth 1 mdy)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
678 nil)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
679
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
680 (defun icalendar--diarytime-to-isotime (timestring ampmstring)
77934
fc20957a3166 (icalendar--diarytime-to-isotime): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 76645
diff changeset
681 "Convert a time like 9:30pm to an iso-conform string like T213000.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
682 In this example the TIMESTRING would be \"9:30\" and the AMPMSTRING
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
683 would be \"pm\"."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
684 (if timestring
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
685 (let ((starttimenum (read (icalendar--rris ":" "" timestring))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
686 ;; take care of am/pm style
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
687 (if (and ampmstring (string= "pm" ampmstring))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
688 (setq starttimenum (+ starttimenum 1200)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
689 (format "T%04d00" starttimenum))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
690 nil))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
691
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
692 (defun icalendar--convert-string-for-export (string)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
693 "Escape comma and other critical characters in STRING."
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
694 (icalendar--rris "," "\\\\," string))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
695
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
696 (defun icalendar--convert-string-for-import (string)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
697 "Remove escape chars for comma, semicolon etc. from STRING."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
698 (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
699 "\\\\n" "\n " (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
700 "\\\\\"" "\"" (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
701 "\\\\;" ";" (icalendar--rris
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
702 "\\\\," "," string)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
703
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
704 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
705 ;; Export -- convert emacs-diary to icalendar
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
706 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
707
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
708 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
709 (defun icalendar-export-file (diary-filename ical-filename)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
710 "Export diary file to iCalendar format.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
711 All diary entries in the file DIARY-FILENAME are converted to iCalendar
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
712 format. The result is appended to the file ICAL-FILENAME."
75141
e4abbe7f7417 (icalendar-import-buffer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 74673
diff changeset
713 (interactive "FExport diary data from file:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
714 Finto iCalendar file: ")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
715 (save-current-buffer
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
716 (set-buffer (find-file diary-filename))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
717 (icalendar-export-region (point-min) (point-max) ical-filename)))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
718
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
719 (defalias 'icalendar-convert-diary-to-ical 'icalendar-export-file)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
720 (make-obsolete 'icalendar-convert-diary-to-ical 'icalendar-export-file)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
721
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
722 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
723 (defun icalendar-export-region (min max ical-filename)
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
724 "Export region in diary file to iCalendar format.
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
725 All diary entries in the region from MIN to MAX in the current buffer are
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
726 converted to iCalendar format. The result is appended to the file
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
727 ICAL-FILENAME.
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
728 This function attempts to return t if something goes wrong. In this
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
729 case an error string which describes all the errors and problems is
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
730 written into the buffer `*icalendar-errors*'."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
731 (interactive "r
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
732 FExport diary data into iCalendar file: ")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
733 (let ((result "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
734 (start 0)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
735 (entry-main "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
736 (entry-rest "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
737 (header "")
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
738 (contents-n-summary)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
739 (contents)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
740 (found-error nil)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
741 (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
742 "?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
743 (other-elements nil))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
744 ;; prepare buffer with error messages
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
745 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
746 (set-buffer (get-buffer-create "*icalendar-errors*"))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
747 (erase-buffer))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
748
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
749 ;; here we go
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
750 (save-excursion
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
751 (goto-char min)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
752 (while (re-search-forward
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
753 "^\\([^ \t\n].+\\)\\(\\(\n[ \t].*\\)*\\)" max t)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
754 (setq entry-main (match-string 1))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
755 (if (match-beginning 2)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
756 (setq entry-rest (match-string 2))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
757 (setq entry-rest ""))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
758 (setq header (format "\nBEGIN:VEVENT\nUID:emacs%d%d%d"
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
759 (car (current-time))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
760 (cadr (current-time))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
761 (car (cddr (current-time)))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
762 (condition-case error-val
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
763 (progn
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
764 (setq contents-n-summary
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
765 (icalendar--convert-to-ical nonmarker entry-main))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
766 (setq other-elements (icalendar--parse-summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
767 (concat entry-main entry-rest)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
768 (setq contents (concat (car contents-n-summary)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
769 "\nSUMMARY:" (cadr contents-n-summary)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
770 (let ((cla (cdr (assoc 'cla other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
771 (des (cdr (assoc 'des other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
772 (loc (cdr (assoc 'loc other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
773 (org (cdr (assoc 'org other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
774 (sta (cdr (assoc 'sta other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
775 (sum (cdr (assoc 'sum other-elements)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
776 (url (cdr (assoc 'url other-elements))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
777 (if cla
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
778 (setq contents (concat contents "\nCLASS:" cla)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
779 (if des
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
780 (setq contents (concat contents "\nDESCRIPTION:" des)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
781 (if loc
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
782 (setq contents (concat contents "\nLOCATION:" loc)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
783 (if org
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
784 (setq contents (concat contents "\nORGANIZER:" org)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
785 (if sta
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
786 (setq contents (concat contents "\nSTATUS:" sta)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
787 ;;(if sum
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
788 ;; (setq contents (concat contents "\nSUMMARY:" sum)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
789 (if url
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
790 (setq contents (concat contents "\nURL:" url))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
791 (setq result (concat result header contents "\nEND:VEVENT")))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
792 ;; handle errors
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
793 (error
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
794 (setq found-error t)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
795 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
796 (set-buffer (get-buffer-create "*icalendar-errors*"))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
797 (insert (format "Error in line %d -- %s: `%s'\n"
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
798 (count-lines (point-min) (point))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
799 (cadr error-val)
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
800 entry-main))))))
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
801
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
802 ;; we're done, insert everything into the file
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
803 (save-current-buffer
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
804 (let ((coding-system-for-write 'utf-8))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
805 (set-buffer (find-file ical-filename))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
806 (goto-char (point-max))
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
807 (insert "BEGIN:VCALENDAR")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
808 (insert "\nPRODID:-//Emacs//NONSGML icalendar.el//EN")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
809 (insert "\nVERSION:2.0")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
810 (insert result)
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
811 (insert "\nEND:VCALENDAR\n")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
812 ;; save the diary file
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
813 (save-buffer)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
814 (unless found-error
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
815 (bury-buffer)))))
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
816 found-error))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
817
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
818 (defun icalendar--convert-to-ical (nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
819 "Convert a diary entry to icalendar format.
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
820 NONMARKER is a regular expression matching the start of non-marking
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
821 entries. ENTRY-MAIN is the first line of the diary entry."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
822 (or
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
823 ;; anniversaries -- %%(diary-anniversary ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
824 (icalendar--convert-anniversary-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
825 ;; cyclic events -- %%(diary-cyclic ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
826 (icalendar--convert-cyclic-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
827 ;; diary-date -- %%(diary-date ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
828 (icalendar--convert-date-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
829 ;; float events -- %%(diary-float ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
830 (icalendar--convert-float-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
831 ;; block events -- %%(diary-block ...)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
832 (icalendar--convert-block-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
833 ;; other sexp diary entries
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
834 (icalendar--convert-sexp-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
835 ;; weekly by day -- Monday 8:30 Team meeting
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
836 (icalendar--convert-weekly-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
837 ;; yearly by day -- 1 May Tag der Arbeit
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
838 (icalendar--convert-yearly-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
839 ;; "ordinary" events, start and end time given
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
840 ;; 1 Feb 2003 blah
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
841 (icalendar--convert-ordinary-to-ical nonmarker entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
842 ;; everything else
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
843 ;; Oops! what's that?
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
844 (error "Could not parse entry")))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
845
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
846 (defun icalendar--parse-summary-and-rest (summary-and-rest)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
847 "Parse SUMMARY-AND-REST from a diary to fill iCalendar properties."
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
848 (save-match-data
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
849 (let* ((s icalendar-import-format)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
850 (p-cla (or (string-match "%c" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
851 (p-des (or (string-match "%d" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
852 (p-loc (or (string-match "%l" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
853 (p-org (or (string-match "%o" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
854 (p-sum (or (string-match "%s" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
855 (p-sta (or (string-match "%t" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
856 (p-url (or (string-match "%u" icalendar-import-format) -1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
857 (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url) '<))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
858 pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
859 (dotimes (i (length p-list))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
860 (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
861 (setq pos-cla (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
862 ((and (>= p-des 0) (= (nth i p-list) p-des))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
863 (setq pos-des (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
864 ((and (>= p-loc 0) (= (nth i p-list) p-loc))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
865 (setq pos-loc (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
866 ((and (>= p-org 0) (= (nth i p-list) p-org))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
867 (setq pos-org (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
868 ((and (>= p-sta 0) (= (nth i p-list) p-sta))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
869 (setq pos-sta (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
870 ((and (>= p-sum 0) (= (nth i p-list) p-sum))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
871 (setq pos-sum (+ 2 (* 2 i))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
872 ((and (>= p-url 0) (= (nth i p-list) p-url))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
873 (setq pos-url (+ 2 (* 2 i))))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
874 (mapc (lambda (ij)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
875 (setq s (icalendar--rris (car ij) (cadr ij) s t t)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
876 (list
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
877 ;; summary must be first! because of %s
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
878 (list "%s"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
879 (concat "\\(" icalendar-import-format-summary "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
880 (list "%c"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
881 (concat "\\(" icalendar-import-format-class "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
882 (list "%d"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
883 (concat "\\(" icalendar-import-format-description "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
884 (list "%l"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
885 (concat "\\(" icalendar-import-format-location "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
886 (list "%o"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
887 (concat "\\(" icalendar-import-format-organizer "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
888 (list "%t"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
889 (concat "\\(" icalendar-import-format-status "\\)?"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
890 (list "%u"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
891 (concat "\\(" icalendar-import-format-url "\\)?"))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
892 (setq s (concat (icalendar--rris "%s" "\\(.*\\)" s nil t) " "))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
893 (if (string-match s summary-and-rest)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
894 (let (cla des loc org sta sum url)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
895 (if (and pos-sum (match-beginning pos-sum))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
896 (setq sum (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
897 (match-beginning pos-sum)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
898 (match-end pos-sum))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
899 (if (and pos-cla (match-beginning pos-cla))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
900 (setq cla (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
901 (match-beginning pos-cla)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
902 (match-end pos-cla))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
903 (if (and pos-des (match-beginning pos-des))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
904 (setq des (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
905 (match-beginning pos-des)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
906 (match-end pos-des))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
907 (if (and pos-loc (match-beginning pos-loc))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
908 (setq loc (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
909 (match-beginning pos-loc)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
910 (match-end pos-loc))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
911 (if (and pos-org (match-beginning pos-org))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
912 (setq org (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
913 (match-beginning pos-org)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
914 (match-end pos-org))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
915 (if (and pos-sta (match-beginning pos-sta))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
916 (setq sta (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
917 (match-beginning pos-sta)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
918 (match-end pos-sta))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
919 (if (and pos-url (match-beginning pos-url))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
920 (setq url (substring summary-and-rest
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
921 (match-beginning pos-url)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
922 (match-end pos-url))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
923 (list (if cla (cons 'cla cla) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
924 (if des (cons 'des des) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
925 (if loc (cons 'loc loc) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
926 (if org (cons 'org org) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
927 (if sta (cons 'sta sta) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
928 ;;(if sum (cons 'sum sum) nil)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
929 (if url (cons 'url url) nil)))))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
930
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
931 ;; subroutines for icalendar-export-region
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
932 (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
933 "Convert \"ordinary\" diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
934 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
935 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
936 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
937 "\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\)\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
938 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
939 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
940 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
941 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
942 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
943 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
944 (let* ((datetime (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
945 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
946 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
947 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
948 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
949 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
950 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
951 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
952 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
953 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
954 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
955 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
956 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
957 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
958 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
959 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
960 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
961 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
962 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
963 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
964 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
965 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
966 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
967 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
968 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
969 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
970 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
971 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
972 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
973 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
974 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
975 (icalendar--dmsg "ordinary %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
976
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
977 (unless startisostring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
978 (error "Could not parse date"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
979 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
980 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
981 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
982 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
983 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
984 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
985 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
986 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
987 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
988 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
989 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
990 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
991 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
992 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
993 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
994 (if starttimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
995 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
996 endisostring)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
997 (or endtimestring ""))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
998 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
999 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1000 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1001
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1002 (defun icalendar--convert-weekly-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1003 "Convert weekly diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1004 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1005 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1006 (if (and (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1007 "\\([a-z]+\\)\\s-+"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1008 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1009 "\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1010 "\\(-0?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1011 "\\([1-9][0-9]?:[0-9][0-9]\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1012 "\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1013 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1014 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1015 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1016 (icalendar--get-weekday-abbrev
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1017 (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1018 (match-end 1))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1019 (let* ((day (icalendar--get-weekday-abbrev
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1020 (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1021 (match-end 1))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1022 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1023 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1024 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1025 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1026 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1027 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1028 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1029 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1030 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1031 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1032 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1033 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1034 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1035 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1036 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1037 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1038 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1039 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1040 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1041 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1042 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1043 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1044 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1045 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1046 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1047 (icalendar--dmsg "weekly %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1048
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1049 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1050 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1051 (let ((time (read
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1052 (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1053 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1054 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1055 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1056 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1057 (if starttimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1058 "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1059 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1060 ;; find the correct week day,
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1061 ;; 1st january 2000 was a saturday
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1062 (format
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1063 "200001%02d"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1064 (+ (icalendar--get-weekday-number day) 2))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1065 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1066 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1067 (if endtimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1068 "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1069 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1070 (format
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1071 "200001%02d"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1072 ;; end is non-inclusive!
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1073 (+ (icalendar--get-weekday-number day)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1074 (if endtimestring 2 3)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1075 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1076 "\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1077 day)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1078 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1079 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1080 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1081
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1082 (defun icalendar--convert-yearly-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1083 "Convert yearly diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1084 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1085 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1086 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1087 (if european-calendar-style
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1088 "0?\\([1-9]+[0-9]?\\)\\s-+\\([a-z]+\\)\\s-+"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1089 "\\([a-z]+\\)\\s-+0?\\([1-9]+[0-9]?\\)\\s-+")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1090 "\\*?\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1091 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1092 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1093 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1094 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1095 "\\s-*\\([^0-9]+.*?\\) ?$" ; must not match years
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1096 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1097 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1098 (let* ((daypos (if european-calendar-style 1 2))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1099 (monpos (if european-calendar-style 2 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1100 (day (read (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1101 (match-beginning daypos)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1102 (match-end daypos))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1103 (month (icalendar--get-month-number
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1104 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1105 (match-beginning monpos)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1106 (match-end monpos))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1107 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1108 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1109 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1110 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1111 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1112 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1113 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1114 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1115 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1116 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1117 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1118 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1119 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1120 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1121 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1122 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1123 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1124 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1125 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1126 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1127 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1128 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1129 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1130 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1131 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1132 (icalendar--dmsg "yearly %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1133
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1134 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1135 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1136 (let ((time (read
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1137 (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1138 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1139 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1140 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1141 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1142 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1143 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1144 (format "1900%02d%02d" month day)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1145 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1146 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1147 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1148 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1149 ;; end is not included! shift by one day
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1150 (icalendar--date-to-isodate
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1151 (list month day 1900)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1152 (if endtimestring 0 1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1153 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1154 "\nRRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1155 (format "%2d" month)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1156 ";BYMONTHDAY="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1157 (format "%2d" day))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1158 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1159 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1160 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1161
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1162 (defun icalendar--convert-sexp-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1163 "Convert complex sexp diary entry to icalendar format -- unsupported!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1164
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1165 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1166
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1167 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1168 entries. ENTRY-MAIN is the first line of the diary entry."
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1169 (cond ((string-match (concat nonmarker
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1170 "%%(and \\(([^)]+)\\))\\(\\s-*.*?\\) ?$")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1171 entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1172 ;; simple sexp entry as generated by icalendar.el: strip off the
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1173 ;; unnecessary (and)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1174 (icalendar--dmsg "diary-sexp from icalendar.el %s" entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1175 (icalendar--convert-to-ical
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1176 nonmarker
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1177 (concat "%%"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1178 (substring entry-main (match-beginning 1) (match-end 1))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1179 (substring entry-main (match-beginning 2) (match-end 2)))))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1180 ((string-match (concat nonmarker
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1181 "%%([^)]+)\\s-*.*")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1182 entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1183 (icalendar--dmsg "diary-sexp %s" entry-main)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1184 (error "Sexp-entries are not supported yet"))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1185 (t
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1186 ;; no match
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1187 nil)))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1188
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1189 (defun icalendar--convert-block-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1190 "Convert block diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1191 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1192 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1193 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1194 "%%(diary-block \\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\)"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1195 " +\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1196 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1197 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1198 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1199 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1200 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1201 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1202 (let* ((startstring (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1203 (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1204 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1205 (endstring (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1206 (match-beginning 2)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1207 (match-end 2)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1208 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1209 startstring))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1210 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1211 endstring))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1212 (endisostring+1 (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1213 endstring 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1214 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1215 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1216 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1217 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1218 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1219 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1220 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1221 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1222 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1223 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1224 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1225 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1226 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1227 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1228 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1229 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1230 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1231 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1232 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1233 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1234 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1235 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1236 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1237 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1238 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1239 (icalendar--dmsg "diary-block %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1240 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1241 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1242 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1243 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1244 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1245 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1246 (+ 10000 time))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1247 (if starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1248 ;; with time -> write rrule
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1249 (list (concat "\nDTSTART;VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1250 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1251 starttimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1252 "\nDTEND;VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1253 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1254 endtimestring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1255 "\nRRULE:FREQ=DAILY;INTERVAL=1;UNTIL="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1256 endisostring)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1257 summary)
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1258 ;; no time -> write long event
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1259 (list (concat "\nDTSTART;VALUE=DATE:" startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1260 "\nDTEND;VALUE=DATE:" endisostring+1)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1261 summary)))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1262 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1263 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1264
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1265 (defun icalendar--convert-float-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1266 "Convert float diary entry to icalendar format -- unsupported!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1267
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1268 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1269
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1270 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1271 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1272 (if (string-match (concat nonmarker
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1273 "%%(diary-float \\([^)]+\\))\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1274 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1275 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1276 (icalendar--dmsg "diary-float %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1277 (error "`diary-float' is not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1278 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1279 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1280
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1281 (defun icalendar--convert-date-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1282 "Convert `diary-date' diary entry to icalendar format -- unsupported!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1283
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1284 FIXME!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1285
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1286 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1287 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1288 (if (string-match (concat nonmarker
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1289 "%%(diary-date \\([^)]+\\))\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1290 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1291 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1292 (icalendar--dmsg "diary-date %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1293 (error "`diary-date' is not supported yet"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1294 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1295 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1296
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1297 (defun icalendar--convert-cyclic-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1298 "Convert `diary-cyclic' diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1299 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1300 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1301 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1302 "%%(diary-cyclic \\([^ ]+\\) +"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1303 "\\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1304 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1305 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1306 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1307 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1308 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1309 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1310 (let* ((frequency (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1311 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1312 (datetime (substring entry-main (match-beginning 2)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1313 (match-end 2)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1314 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1315 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1316 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1317 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1318 (endisostring+1 (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1319 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1320 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1321 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1322 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1323 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1324 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1325 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1326 (if (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1327 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1328 (match-beginning 5)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1329 (match-end 5))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1330 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1331 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1332 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1333 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1334 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1335 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1336 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1337 (if (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1338 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1339 (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1340 (match-end 8))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1341 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1342 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1343 (substring entry-main (match-beginning 9)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1344 (match-end 9)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1345 (icalendar--dmsg "diary-cyclic %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1346 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1347 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1348 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1349 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1350 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1351 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1352 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1353 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1354 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1355 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1356 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1357 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1358 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1359 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1360 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1361 (if endtimestring endisostring endisostring+1)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1362 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1363 "\nRRULE:FREQ=DAILY;INTERVAL=" frequency
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1364 ;; strange: korganizer does not expect
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1365 ;; BYSOMETHING here...
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1366 )
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1367 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1368 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1369 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1370
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1371 (defun icalendar--convert-anniversary-to-ical (nonmarker entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1372 "Convert `diary-anniversary' diary entry to icalendar format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1373 NONMARKER is a regular expression matching the start of non-marking
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1374 entries. ENTRY-MAIN is the first line of the diary entry."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1375 (if (string-match (concat nonmarker
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1376 "%%(diary-anniversary \\([^)]+\\))\\s-*"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1377 "\\(0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1378 "\\("
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1379 "-0?\\([1-9][0-9]?:[0-9][0-9]\\)\\([ap]m\\)?\\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1380 "\\)?"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1381 "\\s-*\\(.*?\\) ?$")
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1382 entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1383 (let* ((datetime (substring entry-main (match-beginning 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1384 (match-end 1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1385 (startisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1386 datetime))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1387 (endisostring (icalendar--datestring-to-isodate
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1388 datetime 1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1389 (starttimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1390 (if (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1391 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1392 (match-beginning 3)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1393 (match-end 3))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1394 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1395 (if (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1396 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1397 (match-beginning 4)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1398 (match-end 4))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1399 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1400 (endtimestring (icalendar--diarytime-to-isotime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1401 (if (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1402 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1403 (match-beginning 6)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1404 (match-end 6))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1405 nil)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1406 (if (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1407 (substring entry-main
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1408 (match-beginning 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1409 (match-end 7))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1410 nil)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1411 (summary (icalendar--convert-string-for-export
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1412 (substring entry-main (match-beginning 8)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1413 (match-end 8)))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1414 (icalendar--dmsg "diary-anniversary %s" entry-main)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1415 (when starttimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1416 (unless endtimestring
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1417 (let ((time
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1418 (read (icalendar--rris "^T0?" ""
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1419 starttimestring))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1420 (setq endtimestring (format "T%06d"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1421 (+ 10000 time))))))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1422 (list (concat "\nDTSTART;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1423 (if starttimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1424 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1425 startisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1426 (or starttimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1427 "\nDTEND;"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1428 (if endtimestring "VALUE=DATE-TIME:"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1429 "VALUE=DATE:")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1430 endisostring
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1431 (or endtimestring "")
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1432 "\nRRULE:FREQ=YEARLY;INTERVAL=1"
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1433 ;; the following is redundant,
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1434 ;; but korganizer seems to expect this... ;(
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1435 ;; and evolution doesn't understand it... :(
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1436 ;; so... who is wrong?!
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1437 ";BYMONTH="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1438 (substring startisostring 4 6)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1439 ";BYMONTHDAY="
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1440 (substring startisostring 6 8))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1441 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1442 ;; no match
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1443 nil))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1444
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1445 ;; ======================================================================
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1446 ;; Import -- convert icalendar to emacs-diary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1447 ;; ======================================================================
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1448
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
1449 ;;;###autoload
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1450 (defun icalendar-import-file (ical-filename diary-filename
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1451 &optional non-marking)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1452 "Import an iCalendar file and append to a diary file.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1453 Argument ICAL-FILENAME output iCalendar file.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1454 Argument DIARY-FILENAME input `diary-file'.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1455 Optional argument NON-MARKING determines whether events are created as
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1456 non-marking or not."
75141
e4abbe7f7417 (icalendar-import-buffer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 74673
diff changeset
1457 (interactive "fImport iCalendar data from file:
e4abbe7f7417 (icalendar-import-buffer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 74673
diff changeset
1458 Finto diary file:
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1459 p")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1460 ;; clean up the diary file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1461 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1462 ;; now load and convert from the ical file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1463 (set-buffer (find-file ical-filename))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1464 (icalendar-import-buffer diary-filename t non-marking)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1465
60382
87759c244379 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60235
diff changeset
1466 ;;;###autoload
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1467 (defun icalendar-import-buffer (&optional diary-file do-not-ask
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1468 non-marking)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1469 "Extract iCalendar events from current buffer.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1470
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1471 This function searches the current buffer for the first iCalendar
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1472 object, reads it and adds all VEVENT elements to the diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1473 DIARY-FILE.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1474
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1475 It will ask for each appointment whether to add it to the diary
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1476 unless DO-NOT-ASK is non-nil. When called interactively,
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1477 DO-NOT-ASK is nil, so that you are asked for each event.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1478
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1479 NON-MARKING determines whether diary events are created as
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1480 non-marking.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1481
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1482 Return code t means that importing worked well, return code nil
75141
e4abbe7f7417 (icalendar-import-buffer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 74673
diff changeset
1483 means that an error has occurred. Error messages will be in the
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1484 buffer `*icalendar-errors*'."
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1485 (interactive)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1486 (save-current-buffer
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1487 ;; prepare ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1488 (message "Preparing icalendar...")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1489 (set-buffer (icalendar--get-unfolded-buffer (current-buffer)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1490 (goto-char (point-min))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1491 (message "Preparing icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1492 (if (re-search-forward "^BEGIN:VCALENDAR\\s-*$" nil t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1493 (let (ical-contents ical-errors)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1494 ;; read ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1495 (message "Reading icalendar...")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1496 (beginning-of-line)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1497 (setq ical-contents (icalendar--read-element nil nil))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1498 (message "Reading icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1499 ;; convert ical
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1500 (message "Converting icalendar...")
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1501 (setq ical-errors (icalendar--convert-ical-to-diary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1502 ical-contents
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1503 diary-file do-not-ask non-marking))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1504 (when diary-file
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1505 ;; save the diary file if it is visited already
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1506 (let ((b (find-buffer-visiting diary-file)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1507 (when b
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1508 (save-current-buffer
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1509 (set-buffer b)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1510 (save-buffer)))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1511 (message "Converting icalendar...done")
75141
e4abbe7f7417 (icalendar-import-buffer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 74673
diff changeset
1512 ;; return t if no error occurred
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1513 (not ical-errors))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1514 (message
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1515 "Current buffer does not contain icalendar contents!")
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1516 ;; return nil, i.e. import did not work
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1517 nil)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1518
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1519 (defalias 'icalendar-extract-ical-from-buffer 'icalendar-import-buffer)
57862
60f1782b5d8d From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57652
diff changeset
1520 (make-obsolete 'icalendar-extract-ical-from-buffer 'icalendar-import-buffer)
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1521
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1522 (defun icalendar--format-ical-event (event)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1523 "Create a string representation of an iCalendar EVENT."
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1524 (let ((string icalendar-import-format)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1525 (conversion-list
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1526 '(("%c" CLASS icalendar-import-format-class)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1527 ("%d" DESCRIPTION icalendar-import-format-description)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1528 ("%l" LOCATION icalendar-import-format-location)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1529 ("%o" ORGANIZER icalendar-import-format-organizer)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1530 ("%s" SUMMARY icalendar-import-format-summary)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1531 ("%t" STATUS icalendar-import-format-status)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1532 ("%u" URL icalendar-import-format-url))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1533 ;; convert the specifiers in the format string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1534 (mapcar (lambda (i)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1535 (let* ((spec (car i))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1536 (prop (cadr i))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1537 (format (car (cddr i)))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1538 (contents (icalendar--get-event-property event prop))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1539 (formatted-contents ""))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1540 (when (and contents (> (length contents) 0))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1541 (setq formatted-contents
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1542 (icalendar--rris "%s"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1543 (icalendar--convert-string-for-import
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1544 contents)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1545 (symbol-value format)
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1546 t t)))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1547 (setq string (icalendar--rris spec
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1548 formatted-contents
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1549 string
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1550 t t))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1551 conversion-list)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1552 string))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1553
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1554 (defun icalendar--convert-ical-to-diary (ical-list diary-file
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1555 &optional do-not-ask
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1556 non-marking)
74673
9963f42a0a19 From Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 68943
diff changeset
1557 "Convert iCalendar data to an Emacs diary file.
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1558 Import VEVENTS from the iCalendar object ICAL-LIST and saves them to a
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1559 DIARY-FILE. If DO-NOT-ASK is nil the user is asked for each event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1560 whether to actually import it. NON-MARKING determines whether diary
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1561 events are created as non-marking.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1562 This function attempts to return t if something goes wrong. In this
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1563 case an error string which describes all the errors and problems is
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1564 written into the buffer `*icalendar-errors*'."
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1565 (let* ((ev (icalendar--all-events ical-list))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1566 (error-string "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1567 (event-ok t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1568 (found-error nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1569 e diary-string)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1570 ;; step through all events/appointments
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1571 (while ev
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1572 (setq e (car ev))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1573 (setq ev (cdr ev))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1574 (setq event-ok nil)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1575 (condition-case error-val
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1576 (let* ((dtstart (icalendar--get-event-property e 'DTSTART))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1577 (dtstart-dec (icalendar--decode-isodatetime dtstart))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1578 (start-d (icalendar--datetime-to-diary-date
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1579 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1580 (start-t (icalendar--datetime-to-colontime dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1581 (dtend (icalendar--get-event-property e 'DTEND))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1582 (dtend-dec (icalendar--decode-isodatetime dtend))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1583 (dtend-1-dec (icalendar--decode-isodatetime dtend -1))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1584 end-d
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1585 end-1-d
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1586 end-t
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1587 (summary (icalendar--convert-string-for-import
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1588 (or (icalendar--get-event-property e 'SUMMARY)
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1589 "No summary")))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1590 (rrule (icalendar--get-event-property e 'RRULE))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1591 (rdate (icalendar--get-event-property e 'RDATE))
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1592 (duration (icalendar--get-event-property e 'DURATION)))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1593 (icalendar--dmsg "%s: `%s'" start-d summary)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1594 ;; check whether start-time is missing
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1595 (if (and dtstart
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1596 (string=
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1597 (cadr (icalendar--get-event-property-attributes
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1598 e 'DTSTART))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1599 "DATE"))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1600 (setq start-t nil))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1601 (when duration
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1602 (let ((dtend-dec-d (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1603 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1604 (icalendar--decode-isoduration duration)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1605 (dtend-1-dec-d (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1606 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1607 (icalendar--decode-isoduration duration
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1608 t))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1609 (if (and dtend-dec (not (eq dtend-dec dtend-dec-d)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1610 (message "Inconsistent endtime and duration for %s"
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1611 summary))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1612 (setq dtend-dec dtend-dec-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1613 (setq dtend-1-dec dtend-1-dec-d)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1614 (setq end-d (if dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1615 (icalendar--datetime-to-diary-date dtend-dec)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1616 start-d))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1617 (setq end-1-d (if dtend-1-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1618 (icalendar--datetime-to-diary-date dtend-1-dec)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1619 start-d))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1620 (setq end-t (if (and
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1621 dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1622 (not (string=
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1623 (cadr
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1624 (icalendar--get-event-property-attributes
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1625 e 'DTEND))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1626 "DATE")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1627 (icalendar--datetime-to-colontime dtend-dec)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1628 start-t))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1629 (icalendar--dmsg "start-d: %s, end-d: %s" start-d end-d)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1630 (cond
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1631 ;; recurring event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1632 (rrule
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1633 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1634 (icalendar--convert-recurring-to-diary e dtstart-dec start-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1635 end-t))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1636 (setq event-ok t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1637 (rdate
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1638 (icalendar--dmsg "rdate event")
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1639 (setq diary-string "")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1640 (mapcar (lambda (datestring)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1641 (setq diary-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1642 (concat diary-string
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1643 (format "......"))))
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1644 (icalendar--split-value rdate)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1645 ;; non-recurring event
60235
025b4fbe4149 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60015
diff changeset
1646 ;; all-day event
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1647 ((not (string= start-d end-d))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1648 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1649 (icalendar--convert-non-recurring-all-day-to-diary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1650 e start-d end-1-d))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1651 (setq event-ok t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1652 ;; not all-day
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1653 ((and start-t (or (not end-t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1654 (not (string= start-t end-t))))
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1655 (setq diary-string
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1656 (icalendar--convert-non-recurring-not-all-day-to-diary
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1657 e dtstart-dec dtend-dec start-t end-t))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1658 (setq event-ok t))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1659 ;; all-day event
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1660 (t
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1661 (icalendar--dmsg "all day event")
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1662 (setq diary-string (icalendar--datetime-to-diary-date
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1663 dtstart-dec "/"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1664 (setq event-ok t)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1665 ;; add all other elements unless the user doesn't want to have
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1666 ;; them
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1667 (if event-ok
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1668 (progn
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1669 (setq diary-string
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1670 (concat diary-string " "
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1671 (icalendar--format-ical-event e)))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1672 (if do-not-ask (setq summary nil))
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1673 ;; add entry to diary and store actual name of diary
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1674 ;; file (in case it was nil)
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1675 (setq diary-file
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1676 (icalendar--add-diary-entry diary-string diary-file
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1677 non-marking summary)))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1678 ;; event was not ok
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1679 (setq found-error t)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1680 (setq error-string
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1681 (format "%s\nCannot handle this event:%s"
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1682 error-string e))))
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1683 ;; FIXME: inform user about ignored event properties
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1684 ;; handle errors
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1685 (error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1686 (message "Ignoring event \"%s\"" e)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1687 (setq found-error t)
60015
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1688 (setq error-string (format "%s\n%s\nCannot handle this event: %s"
7152e45c561a From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57862
diff changeset
1689 error-val error-string e))
65591
a65f8ec418fc message format spec fixes, commit # 10
Deepak Goel <deego@gnufans.org>
parents: 64432
diff changeset
1690 (message "%s" error-string))))
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1691
74673
9963f42a0a19 From Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 68943
diff changeset
1692 ;; insert final newline
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1693 (if diary-file
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1694 (let ((b (find-buffer-visiting diary-file)))
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1695 (when b
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1696 (save-current-buffer
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1697 (set-buffer b)
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1698 (goto-char (point-max))
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1699 (insert "\n")))))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1700 (if found-error
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1701 (save-current-buffer
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1702 (set-buffer (get-buffer-create "*icalendar-errors*"))
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1703 (erase-buffer)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1704 (insert error-string)))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1705 (message "Converting icalendar...done")
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1706 found-error))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1707
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1708 ;; subroutines for importing
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1709 (defun icalendar--convert-recurring-to-diary (e dtstart-dec start-t end-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1710 "Convert recurring icalendar event E to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1711
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1712 DTSTART-DEC is the DTSTART property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1713 START-T is the event's start time in diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1714 END-T is the event's end time in diary format."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1715 (icalendar--dmsg "recurring event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1716 (let* ((rrule (icalendar--get-event-property e 'RRULE))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1717 (rrule-props (icalendar--split-value rrule))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1718 (frequency (cadr (assoc 'FREQ rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1719 (until (cadr (assoc 'UNTIL rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1720 (count (cadr (assoc 'COUNT rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1721 (interval (read (or (cadr (assoc 'INTERVAL rrule-props)) "1")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1722 (dtstart-conv (icalendar--datetime-to-diary-date dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1723 (until-conv (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1724 (icalendar--decode-isodatetime until)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1725 (until-1-conv (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1726 (icalendar--decode-isodatetime until -1)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1727 (result ""))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1728
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1729 ;; FIXME FIXME interval!!!!!!!!!!!!!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1730
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1731 (when count
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1732 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1733 (message "Must not have UNTIL and COUNT -- ignoring COUNT element!")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1734 (let ((until-1 0))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1735 (cond ((string-equal frequency "DAILY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1736 (setq until (icalendar--add-decoded-times
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1737 dtstart-dec
62053
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1738 (list 0 0 0 (* (read count) interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1739 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1740 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1741 (list 0 0 0 (* (- (read count) 1) interval)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1742 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1743 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1744 ((string-equal frequency "WEEKLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1745 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1746 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1747 (list 0 0 0 (* (read count) 7 interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1748 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1749 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1750 (list 0 0 0 (* (- (read count) 1) 7
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1751 interval) 0 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1752 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1753 ((string-equal frequency "MONTHLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1754 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1755 dtstart-dec (list 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1756 interval) 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1757 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1758 dtstart-dec (list 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1759 interval) 0)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1760 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1761 ((string-equal frequency "YEARLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1762 (setq until (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1763 dtstart-dec (list 0 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1764 interval))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1765 (setq until-1 (icalendar--add-decoded-times
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1766 dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1767 (list 0 0 0 0 0 (* (- (read count) 1)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1768 interval))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1769 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1770 (t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1771 (message "Cannot handle COUNT attribute for `%s' events."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1772 frequency)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1773 (setq until-conv (icalendar--datetime-to-diary-date until))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1774 (setq until-1-conv (icalendar--datetime-to-diary-date until-1))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1775 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1776 )
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1777 (cond ((string-equal frequency "WEEKLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1778 (if (not start-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1779 (progn
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1780 ;; weekly and all-day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1781 (icalendar--dmsg "weekly all-day")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1782 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1783 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1784 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1785 (concat "%%%%(and "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1786 "(diary-cyclic %d %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1787 "(diary-block %s %s))")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1788 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1789 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1790 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1791 (if count until-1-conv until-conv)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1792 ))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1793 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1794 (format "%%%%(and (diary-cyclic %d %s))"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1795 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1796 dtstart-conv))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1797 ;; weekly and not all-day
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1798 (let* ((byday (cadr (assoc 'BYDAY rrule-props)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1799 (weekday
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1800 (icalendar--get-weekday-number byday)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1801 (icalendar--dmsg "weekly not-all-day")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1802 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1803 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1804 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1805 (concat "%%%%(and "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1806 "(diary-cyclic %d %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1807 "(diary-block %s %s)) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1808 "%s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1809 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1810 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1811 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1812 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1813 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1814 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1815 ;; no limit
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1816 ;; FIXME!!!!
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1817 ;; DTSTART;VALUE=DATE-TIME:20030919T090000
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1818 ;; DTEND;VALUE=DATE-TIME:20030919T113000
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1819 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1820 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1821 "%%%%(and (diary-cyclic %s %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1822 (* interval 7)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1823 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1824 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1825 (if end-t "-" "") (or end-t "")))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1826 ;; yearly
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1827 ((string-equal frequency "YEARLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1828 (icalendar--dmsg "yearly")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1829 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1830 (setq result (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1831 (concat "%%%%(and (diary-date %s %s t) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1832 "(diary-block %s %s)) %s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1833 (if european-calendar-style (nth 3 dtstart-dec)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1834 (nth 4 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1835 (if european-calendar-style (nth 4 dtstart-dec)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1836 (nth 3 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1837 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1838 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1839 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1840 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1841 (setq result (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1842 "%%%%(and (diary-anniversary %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1843 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1844 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1845 (if end-t "-" "") (or end-t "")))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1846 ;; monthly
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1847 ((string-equal frequency "MONTHLY")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1848 (icalendar--dmsg "monthly")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1849 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1850 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1851 "%%%%(and (diary-date %s %s %s) (diary-block %s %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1852 (if european-calendar-style (nth 3 dtstart-dec) "t")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1853 (if european-calendar-style "t" (nth 3 dtstart-dec))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1854 "t"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1855 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1856 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1857 until-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1858 "1 1 9999") ;; FIXME: should be unlimited
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1859 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1860 (if end-t "-" "") (or end-t ""))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1861 ;; daily
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1862 ((and (string-equal frequency "DAILY"))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1863 (if until
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1864 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1865 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1866 (concat "%%%%(and (diary-cyclic %s %s) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1867 "(diary-block %s %s)) %s%s%s")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1868 interval dtstart-conv dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1869 (if count until-1-conv until-conv)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1870 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1871 (if end-t "-" "") (or end-t "")))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1872 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1873 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1874 "%%%%(and (diary-cyclic %s %s)) %s%s%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1875 interval
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1876 dtstart-conv
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1877 (or start-t "")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1878 (if end-t "-" "") (or end-t ""))))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1879 ;; Handle exceptions from recurrence rules
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1880 (let ((ex-dates (icalendar--get-event-properties e 'EXDATE)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1881 (while ex-dates
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1882 (let* ((ex-start (icalendar--decode-isodatetime
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1883 (car ex-dates)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1884 (ex-d (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1885 ex-start)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1886 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1887 (icalendar--rris "^%%(\\(and \\)?"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1888 (format
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1889 "%%%%(and (not (diary-date %s)) "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1890 ex-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1891 result)))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1892 (setq ex-dates (cdr ex-dates))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1893 ;; FIXME: exception rules are not recognized
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1894 (if (icalendar--get-event-property e 'EXRULE)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1895 (setq result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1896 (concat result
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1897 "\n Exception rules: "
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1898 (icalendar--get-event-properties
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1899 e 'EXRULE))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1900 result))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1901
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1902 (defun icalendar--convert-non-recurring-all-day-to-diary (event start-d end-d)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1903 "Convert non-recurring icalendar EVENT to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1904
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1905 DTSTART is the decoded DTSTART property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1906 Argument START-D gives the first day.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1907 Argument END-D gives the last day."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1908 (icalendar--dmsg "non-recurring all-day event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1909 (format "%%%%(and (diary-block %s %s))" start-d end-d))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1910
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1911 (defun icalendar--convert-non-recurring-not-all-day-to-diary (event dtstart-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1912 dtend-dec
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1913 start-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1914 end-t)
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1915 "Convert recurring icalendar EVENT to diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1916
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1917 DTSTART-DEC is the decoded DTSTART property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1918 DTEND-DEC is the decoded DTEND property of E.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1919 START-T is the event's start time in diary format.
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1920 END-T is the event's end time in diary format."
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1921 (icalendar--dmsg "not all day event")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1922 (cond (end-t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1923 (format "%s %s-%s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1924 (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1925 dtstart-dec "/")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1926 start-t end-t))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1927 (t
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1928 (format "%s %s"
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1929 (icalendar--datetime-to-diary-date
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1930 dtstart-dec "/")
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1931 start-t))))
57aabea77432 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 60382
diff changeset
1932
57586
376b47c63cfd From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 57345
diff changeset
1933 (defun icalendar--add-diary-entry (string diary-file non-marking
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1934 &optional summary)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1935 "Add STRING to the diary file DIARY-FILE.
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1936 STRING must be a properly formatted valid diary entry. NON-MARKING
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1937 determines whether diary events are created as non-marking. If
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1938 SUMMARY is not nil it must be a string that gives the summary of the
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1939 entry. In this case the user will be asked whether he wants to insert
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1940 the entry."
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1941 (when (or (not summary)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1942 (y-or-n-p (format "Add appointment for `%s' to diary? "
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1943 summary)))
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1944 (when summary
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1945 (setq non-marking
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1946 (y-or-n-p (format "Make appointment non-marking? "))))
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1947 (save-window-excursion
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1948 (unless diary-file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1949 (setq diary-file
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1950 (read-file-name "Add appointment to this diary file: ")))
66374
88fc54347c68 From Ulf Jasper <ulf.jasper@web.de>:
Glenn Morris <rgm@gnu.org>
parents: 65591
diff changeset
1951 ;; Note: make-diary-entry will add a trailing blank char.... :(
76645
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1952 (make-diary-entry string non-marking diary-file)))
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1953 ;; return diary-file in case it has been changed interactively
fe0cd0081a51 Ulf Jasper <ulf.jasper at web.de>:
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
1954 diary-file)
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1955
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1956 (provide 'icalendar)
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1957
57345
f024640dc5e4 Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 57337
diff changeset
1958 ;; arch-tag: 74fdbe8e-0451-4e38-bb61-4416e822f4fc
57337
a1b1850b5a47 New file, from Ulf Jasper <ulf.jasper@web.de>.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1959 ;;; icalendar.el ends here