aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Jasper2011-04-27 19:48:35 +0200
committerUlf Jasper2011-04-27 19:48:35 +0200
commit211ec9072dc2635bf027ae6b3c58a3edf27e5969 (patch)
tree4a14e6873ab2e1334c98dfe3eac11b7f511e2c8d
parent2a782793a8596e6724207474bd7545684c83591d (diff)
downloademacs-211ec9072dc2635bf027ae6b3c58a3edf27e5969.tar.gz
emacs-211ec9072dc2635bf027ae6b3c58a3edf27e5969.zip
Applied icalendar patches from Niels Giesen.
lisp/ChangeLog: 2011-04-27 Niels Giesen <niels.giesen@gmail.com> * calendar/icalendar.el (diary-lib): Added require statement. (icalendar--create-uid): Read out a uid from a text-property on the first character in the entry. This allows for code to add its own uid to the entry. (icalendar--convert-float-to-ical): Add export of `diary-float'-entries save for those with the optional DAY
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/calendar/icalendar.el119
2 files changed, 96 insertions, 33 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e6517f77b32..ed73044f6f0 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12011-04-27 Niels Giesen <niels.giesen@gmail.com>
2
3 * calendar/icalendar.el (diary-lib): Added require statement.
4 (icalendar--create-uid): Read out a uid from a text-property on
5 the first character in the entry. This allows for code to add its
6 own uid to the entry.
7 (icalendar--convert-float-to-ical): Add export of
8 `diary-float'-entries save for those with the optional DAY
9 argument.
10
12011-04-27 Daniel Colascione <dan.colascione@gmail.com> 112011-04-27 Daniel Colascione <dan.colascione@gmail.com>
2 12
3 * subr.el (shell-quote-argument): Use alternate escaping strategy 13 * subr.el (shell-quote-argument): Use alternate escaping strategy
diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el
index ca88548138b..03456ba36f2 100644
--- a/lisp/calendar/icalendar.el
+++ b/lisp/calendar/icalendar.el
@@ -34,6 +34,8 @@
34;; week of the year 2000 when they are exported. 34;; week of the year 2000 when they are exported.
35;; - Yearly diary entries are assumed to occur the first time in the year 35;; - Yearly diary entries are assumed to occur the first time in the year
36;; 1900 when they are exported. 36;; 1900 when they are exported.
37;; - Float diary entries are assumed to occur the first time on the
38;; day when they are exported.
37 39
38;;; History: 40;;; History:
39 41
@@ -241,6 +243,7 @@ code for the event, and your personal domain name."
241;; all the other libs we need 243;; all the other libs we need
242;; ====================================================================== 244;; ======================================================================
243(require 'calendar) 245(require 'calendar)
246(require 'diary-lib)
244 247
245;; ====================================================================== 248;; ======================================================================
246;; misc 249;; misc
@@ -925,27 +928,30 @@ ENTRY-FULL is the full diary entry string. CONTENTS is the
925current iCalendar object, as a string. Increase 928current iCalendar object, as a string. Increase
926`icalendar--uid-count'. Returns the UID string." 929`icalendar--uid-count'. Returns the UID string."
927 (let ((uid icalendar-uid-format)) 930 (let ((uid icalendar-uid-format))
928 931 (if
929 (setq uid (replace-regexp-in-string 932 ;; Allow other apps (such as org-mode) to create its own uid
930 "%c" 933 (get-text-property 0 'uid entry-full)
931 (format "%d" icalendar--uid-count) 934 (setq uid (get-text-property 0 'uid entry-full))
932 uid t t)) 935 (setq uid (replace-regexp-in-string
933 (setq icalendar--uid-count (1+ icalendar--uid-count)) 936 "%c"
934 (setq uid (replace-regexp-in-string 937 (format "%d" icalendar--uid-count)
935 "%t" 938 uid t t))
936 (format "%d%d%d" (car (current-time)) 939 (setq icalendar--uid-count (1+ icalendar--uid-count))
937 (cadr (current-time)) 940 (setq uid (replace-regexp-in-string
938 (car (cddr (current-time)))) 941 "%t"
939 uid t t)) 942 (format "%d%d%d" (car (current-time))
940 (setq uid (replace-regexp-in-string 943 (cadr (current-time))
941 "%h" 944 (car (cddr (current-time))))
942 (format "%d" (abs (sxhash entry-full))) uid t t)) 945 uid t t))
943 (setq uid (replace-regexp-in-string 946 (setq uid (replace-regexp-in-string
944 "%u" (or user-login-name "UNKNOWN_USER") uid t t)) 947 "%h"
945 (let ((dtstart (if (string-match "^DTSTART[^:]*:\\([0-9]*\\)" contents) 948 (format "%d" (abs (sxhash entry-full))) uid t t))
946 (substring contents (match-beginning 1) (match-end 1)) 949 (setq uid (replace-regexp-in-string
947 "DTSTART"))) 950 "%u" (or user-login-name "UNKNOWN_USER") uid t t))
948 (setq uid (replace-regexp-in-string "%s" dtstart uid t t))) 951 (let ((dtstart (if (string-match "^DTSTART[^:]*:\\([0-9]*\\)" contents)
952 (substring contents (match-beginning 1) (match-end 1))
953 "DTSTART")))
954 (setq uid (replace-regexp-in-string "%s" dtstart uid t t))))
949 955
950 ;; Return the UID string 956 ;; Return the UID string
951 uid)) 957 uid))
@@ -1545,18 +1551,65 @@ entries. ENTRY-MAIN is the first line of the diary entry."
1545 nil)) 1551 nil))
1546 1552
1547(defun icalendar--convert-float-to-ical (nonmarker entry-main) 1553(defun icalendar--convert-float-to-ical (nonmarker entry-main)
1548 "Convert float diary entry to icalendar format -- unsupported! 1554 "Convert float diary entry to icalendar format -- partially unsupported!
1549 1555
1550FIXME! 1556 FIXME! DAY from diary-float yet unimplemented.
1551 1557
1552NONMARKER is a regular expression matching the start of non-marking 1558 NONMARKER is a regular expression matching the start of non-marking
1553entries. ENTRY-MAIN is the first line of the diary entry." 1559 entries. ENTRY-MAIN is the first line of the diary entry."
1554 (if (string-match (concat nonmarker 1560 (if (string-match (concat nonmarker "%%\\((diary-float .+\\) ?$") entry-main)
1555 "%%(diary-float \\([^)]+\\))\\s-*\\(.*?\\) ?$") 1561 (with-temp-buffer
1556 entry-main) 1562 (insert (match-string 1 entry-main))
1557 (progn 1563 (goto-char (point-min))
1558 (icalendar--dmsg "diary-float %s" entry-main) 1564 (let* ((sexp (read (current-buffer))) ;using `read' here
1559 (error "`diary-float' is not supported yet")) 1565 ;easier than regexp
1566 ;matching, esp. with
1567 ;different forms of
1568 ;MONTH
1569 (month (nth 1 sexp))
1570 (dayname (nth 2 sexp))
1571 (n (nth 3 sexp))
1572 (day (nth 4 sexp))
1573 (summary
1574 (replace-regexp-in-string
1575 "\\(^\s+\\|\s+$\\)" ""
1576 (buffer-substring (point) (point-max)))))
1577
1578 (when day
1579 (progn
1580 (icalendar--dmsg "diary-float %s" entry-main)
1581 (error "Don't know if or how to implement day in `diary-float'")))
1582
1583 (list (concat
1584 ;;Start today (yes this is an arbitrary choice):
1585 "\nDTSTART;VALUE=DATE:"
1586 (format-time-string "%Y%m%d" (current-time))
1587 ;;BUT remove today if `diary-float'
1588 ;;expression does not hold true for today:
1589 (when
1590 (null (let ((date (calendar-current-date))
1591 (entry entry-main))
1592 (diary-float month dayname n)))
1593 (concat
1594 "\nEXDATE;VALUE=DATE:"
1595 (format-time-string "%Y%m%d" (current-time))))
1596 "\nRRULE:"
1597 (if (or (numberp month) (listp month))
1598 "FREQ=YEARLY;BYMONTH="
1599 "FREQ=MONTHLY")
1600 (when
1601 (listp month)
1602 (mapconcat
1603 (lambda (m)
1604 (number-to-string m))
1605 (cadr month) ","))
1606 (when
1607 (numberp month)
1608 (number-to-string month))
1609 ";BYDAY="
1610 (number-to-string n)
1611 (aref icalendar--weekday-array dayname))
1612 summary)))
1560 ;; no match 1613 ;; no match
1561 nil)) 1614 nil))
1562 1615