>From a2db198dae5210fa3d2a4353667f2c75d28cd16a Mon Sep 17 00:00:00 2001 From: Niels Giesen Date: Sat, 12 Feb 2011 18:12:16 +0100 Subject: [PATCH 2/2] Export `diary-float' entries. * lisp/calendar/icalendar.el (require 'diary-lib): diary-lib required by code now used in `icalendar--convert-float-to-ical'. * lisp/calendar/icalendar.el (icalendar--convert-float-to-ical): Implement the body of this function instead of backing out. This change implements the export of `diary-float' entries save for those with the optional day entry. The current date is used as the start date (but excluded if the current date does not match the `diary-float' arguments). The use of the current date as the start date is quite arbitrary, in the same way as the start dates for weekly and yearly events are arbitrary. It might be wise to bring the behaviour for these different entries more in line with each other, perhaps leaving the user a choice via customization. --- lisp/calendar/icalendar.el | 74 ++++++++++++++++++++++++++++++++++++------- 1 files changed, 62 insertions(+), 12 deletions(-) diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index b1d2bba..38a74df 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el @@ -34,6 +34,8 @@ ;; week of the year 2000 when they are exported. ;; - Yearly diary entries are assumed to occur the first time in the year ;; 1900 when they are exported. +;; - Float diary entries are assumed to occur the first time on the +;; day when they are exported. ;;; History: @@ -241,6 +243,7 @@ code for the event, and your personal domain name." ;; all the other libs we need ;; ====================================================================== (require 'calendar) +(require 'diary-lib) ;; ====================================================================== ;; misc @@ -1548,18 +1551,65 @@ entries. ENTRY-MAIN is the first line of the diary entry." nil)) (defun icalendar--convert-float-to-ical (nonmarker entry-main) - "Convert float diary entry to icalendar format -- unsupported! - -FIXME! - -NONMARKER is a regular expression matching the start of non-marking -entries. ENTRY-MAIN is the first line of the diary entry." - (if (string-match (concat nonmarker - "%%(diary-float \\([^)]+\\))\\s-*\\(.*?\\) ?$") - entry-main) - (progn - (icalendar--dmsg "diary-float %s" entry-main) - (error "`diary-float' is not supported yet")) + "Convert float diary entry to icalendar format -- partially unsupported! + + FIXME! DAY from diary-float yet unimplemented. + + NONMARKER is a regular expression matching the start of non-marking + entries. ENTRY-MAIN is the first line of the diary entry." + (if (string-match (concat nonmarker "%%\\((diary-float .+\\) ?$") entry-main) + (with-temp-buffer + (insert (match-string 1 entry-main)) + (goto-char (point-min)) + (let* ((sexp (read (current-buffer))) ;using `read' here + ;easier than regexp + ;matching, esp. with + ;different forms of + ;MONTH + (month (nth 1 sexp)) + (dayname (nth 2 sexp)) + (n (nth 3 sexp)) + (day (nth 4 sexp)) + (summary + (replace-regexp-in-string + "\\(^\s+\\|\s+$\\)" "" + (buffer-substring (point) (point-max))))) + + (when day + (progn + (icalendar--dmsg "diary-float %s" entry-main) + (error "Don't know if or how to implement day in `diary-float'"))) + + (list (concat + ;;Start today (yes this is an arbitrary choice): + "\nDTSTART;VALUE=DATE:" + (format-time-string "%Y%m%d" (current-time)) + ;;BUT remove today if `diary-float' + ;;expression does not hold true for today: + (when + (null (let ((date (calendar-current-date)) + (entry entry-main)) + (diary-float month dayname n))) + (concat + "\nEXDATE;VALUE=DATE:" + (format-time-string "%Y%m%d" (current-time)))) + "\nRRULE:" + (if (or (numberp month) (listp month)) + "FREQ=YEARLY;BYMONTH=" + "FREQ=MONTHLY") + (when + (listp month) + (mapconcat + (lambda (m) + (number-to-string m)) + (cadr month) ",")) + (when + (numberp month) + (number-to-string month)) + ";BYDAY=" + (number-to-string n) + (aref icalendar--weekday-array dayname)) + summary))) ;; no match nil)) -- 1.7.1