emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/calendar/icalendar.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/calendar/icalendar.el,v
Date: Sat, 26 Jan 2008 20:19:17 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       08/01/26 20:19:17

Index: icalendar.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/calendar/icalendar.el,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- icalendar.el        16 Jan 2008 04:13:31 -0000      1.26
+++ icalendar.el        26 Jan 2008 20:19:16 -0000      1.27
@@ -105,7 +105,7 @@
 
 ;;; Code:
 
-(defconst icalendar-version "0.16"
+(defconst icalendar-version "0.17"
   "Version number of icalendar.el.")
 
 ;; ======================================================================
@@ -118,17 +118,25 @@
 
 (defcustom icalendar-import-format
   "%s%d%l%o"
-  "Format string for importing events from iCalendar into Emacs diary.
-This string defines how iCalendar events are inserted into diary
-file.  Meaning of the specifiers:
+  "Format for importing events from iCalendar into Emacs diary.
+It defines how iCalendar events are inserted into diary file.
+This may either be a string or a function.
+
+In case of a formatting STRING the following specifiers can be used:
 %c Class, see `icalendar-import-format-class'
 %d Description, see `icalendar-import-format-description'
 %l Location, see `icalendar-import-format-location'
 %o Organizer, see `icalendar-import-format-organizer'
 %s Summary, see `icalendar-import-format-summary'
 %t Status, see `icalendar-import-format-status'
-%u URL, see `icalendar-import-format-url'"
-  :type 'string
+%u URL, see `icalendar-import-format-url'
+
+A formatting FUNCTION will be called with a VEVENT as its only
+argument.  It must return a string.  See
+`icalendar-import-format-sample' for an example."
+  :type '(choice
+          (string :tag "String")
+          (function :tag "Function"))
   :group 'icalendar)
 
 (defcustom icalendar-import-format-summary
@@ -247,7 +255,7 @@
 INVALUE gives the current iCalendar element we are reading.
 INPARAMS gives the current parameters.....
 This function calls itself recursively for each nested calendar element
-it finds"
+it finds."
   (let (element children line name params param param-name param-value
                 value
                 (continue t))
@@ -923,8 +931,13 @@
    (error "Could not parse entry")))
 
 (defun icalendar--parse-summary-and-rest (summary-and-rest)
-  "Parse SUMMARY-AND-REST from a diary to fill iCalendar properties."
+  "Parse SUMMARY-AND-REST from a diary to fill iCalendar properties.
+Returns an alist."
   (save-match-data
+    (if (functionp icalendar-import-format)
+        ;; can't do anything
+        nil
+      ;; split summary-and-rest
     (let* ((s icalendar-import-format)
            (p-cla (or (string-match "%c" icalendar-import-format) -1))
            (p-des (or (string-match "%d" icalendar-import-format) -1))
@@ -955,20 +968,21 @@
             (list
              ;; summary must be first! because of %s
              (list "%s"
-                   (concat "\\(" icalendar-import-format-summary "\\)?"))
+                     (concat "\\(" icalendar-import-format-summary "\\)??"))
              (list "%c"
-                   (concat "\\(" icalendar-import-format-class "\\)?"))
+                     (concat "\\(" icalendar-import-format-class "\\)??"))
              (list "%d"
-                   (concat "\\(" icalendar-import-format-description "\\)?"))
+                     (concat "\\(" icalendar-import-format-description 
"\\)??"))
              (list "%l"
-                   (concat "\\(" icalendar-import-format-location "\\)?"))
+                     (concat "\\(" icalendar-import-format-location "\\)??"))
              (list "%o"
-                   (concat "\\(" icalendar-import-format-organizer "\\)?"))
+                     (concat "\\(" icalendar-import-format-organizer "\\)??"))
              (list "%t"
-                   (concat "\\(" icalendar-import-format-status "\\)?"))
+                     (concat "\\(" icalendar-import-format-status "\\)??"))
              (list "%u"
-                   (concat "\\(" icalendar-import-format-url "\\)?"))))
-      (setq s (concat (icalendar--rris "%s" "\\(.*\\)" s nil t) " "))
+                     (concat "\\(" icalendar-import-format-url "\\)??"))))
+        (setq s (concat "^" (icalendar--rris "%s" "\\(.*?\\)" s nil t)
+                        " $"))
       (if (string-match s summary-and-rest)
           (let (cla des loc org sta sum url)
             (if (and pos-sum (match-beginning pos-sum))
@@ -1005,7 +1019,7 @@
                   (if org (cons 'org org) nil)
                   (if sta (cons 'sta sta) nil)
                   ;;(if sum (cons 'sum sum) nil)
-                  (if url (cons 'url url) nil)))))))
+                    (if url (cons 'url url) nil))))))))
 
 ;; subroutines for icalendar-export-region
 (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main)
@@ -1600,6 +1614,8 @@
 
 (defun icalendar--format-ical-event (event)
   "Create a string representation of an iCalendar EVENT."
+  (if (functionp icalendar-import-format)
+      (funcall icalendar-import-format event)
   (let ((string icalendar-import-format)
         (conversion-list
          '(("%c" CLASS       icalendar-import-format-class)
@@ -1628,7 +1644,7 @@
                                            string
                                            t t))))
          conversion-list)
-    string))
+    string)))
 
 (defun icalendar--convert-ical-to-diary (ical-list diary-file
                                                    &optional do-not-ask
@@ -2044,6 +2060,21 @@
   ;; return diary-file in case it has been changed interactively
   diary-file)
 
+;; ======================================================================
+;; Examples
+;; ======================================================================
+(defun icalendar-import-format-sample (event)
+  "Example function for formatting an icalendar EVENT."
+  (format (concat "SUMMARY=`%s' DESCRIPTION=`%s' LOCATION=`%s' ORGANIZER=`%s' "
+                  "STATUS=`%s' URL=`%s' CLASS=`%s'")
+          (or (icalendar--get-event-property event 'SUMMARY) "")
+          (or (icalendar--get-event-property event 'DESCRIPTION) "")
+          (or (icalendar--get-event-property event 'LOCATION) "")
+          (or (icalendar--get-event-property event 'ORGANIZER) "")
+          (or (icalendar--get-event-property event 'STATUS) "")
+          (or (icalendar--get-event-property event 'URL) "")
+          (or (icalendar--get-event-property event 'CLASS) "")))
+
 (provide 'icalendar)
 
 ;; arch-tag: 74fdbe8e-0451-4e38-bb61-4416e822f4fc




reply via email to

[Prev in Thread] Current Thread [Next in Thread]