aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2008-01-26 20:20:20 +0000
committerGlenn Morris2008-01-26 20:20:20 +0000
commitb3360383c8de7fc50ee5107f8863c873cacc8f4a (patch)
tree0aafa5635f8f5a6ac09608d477dc8179b55da9de
parent832ffa7c8ef161baba18792b6e26065c19d5b15c (diff)
downloademacs-b3360383c8de7fc50ee5107f8863c873cacc8f4a.tar.gz
emacs-b3360383c8de7fc50ee5107f8863c873cacc8f4a.zip
Ulf Jasper <ulf.jasper at web.de>
(icalendar-version): Increase to "0.17". (icalendar-import-format): Doc fix. Allow function type. (icalendar--read-element): Doc fix. (icalendar--parse-summary-and-rest): Doc fix. Handle function type icalendar-import-format. Make regexps non-greedy. (icalendar--format-ical-event): Handle function type icalendar-import-format. (icalendar-import-format-sample): New function.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/calendar/icalendar.el213
2 files changed, 133 insertions, 91 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9d87c313f3a..d7f34bd3f46 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12008-01-20 Ulf Jasper <ulf.jasper@web.de>
2
3 * icalendar.el (icalendar-version): Increase to "0.17".
4 (icalendar-import-format): Doc fix. Allow function type.
5 (icalendar--read-element): Doc fix.
6 (icalendar--parse-summary-and-rest): Doc fix. Handle function
7 type icalendar-import-format. Make regexps non-greedy.
8 (icalendar--format-ical-event): Handle function type
9 icalendar-import-format.
10 (icalendar-import-format-sample): New function.
11
12008-01-26 Thien-Thi Nguyen <ttn@gnuvola.org> 122008-01-26 Thien-Thi Nguyen <ttn@gnuvola.org>
2 13
3 * vc.el (vc-exec-after): For mode-line-process highlighting, if 14 * vc.el (vc-exec-after): For mode-line-process highlighting, if
diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el
index b05598b6a27..62cc247e8de 100644
--- a/lisp/calendar/icalendar.el
+++ b/lisp/calendar/icalendar.el
@@ -105,7 +105,7 @@
105 105
106;;; Code: 106;;; Code:
107 107
108(defconst icalendar-version "0.16" 108(defconst icalendar-version "0.17"
109 "Version number of icalendar.el.") 109 "Version number of icalendar.el.")
110 110
111;; ====================================================================== 111;; ======================================================================
@@ -118,17 +118,25 @@
118 118
119(defcustom icalendar-import-format 119(defcustom icalendar-import-format
120 "%s%d%l%o" 120 "%s%d%l%o"
121 "Format string for importing events from iCalendar into Emacs diary. 121 "Format for importing events from iCalendar into Emacs diary.
122This string defines how iCalendar events are inserted into diary 122It defines how iCalendar events are inserted into diary file.
123file. Meaning of the specifiers: 123This may either be a string or a function.
124
125In case of a formatting STRING the following specifiers can be used:
124%c Class, see `icalendar-import-format-class' 126%c Class, see `icalendar-import-format-class'
125%d Description, see `icalendar-import-format-description' 127%d Description, see `icalendar-import-format-description'
126%l Location, see `icalendar-import-format-location' 128%l Location, see `icalendar-import-format-location'
127%o Organizer, see `icalendar-import-format-organizer' 129%o Organizer, see `icalendar-import-format-organizer'
128%s Summary, see `icalendar-import-format-summary' 130%s Summary, see `icalendar-import-format-summary'
129%t Status, see `icalendar-import-format-status' 131%t Status, see `icalendar-import-format-status'
130%u URL, see `icalendar-import-format-url'" 132%u URL, see `icalendar-import-format-url'
131 :type 'string 133
134A formatting FUNCTION will be called with a VEVENT as its only
135argument. It must return a string. See
136`icalendar-import-format-sample' for an example."
137 :type '(choice
138 (string :tag "String")
139 (function :tag "Function"))
132 :group 'icalendar) 140 :group 'icalendar)
133 141
134(defcustom icalendar-import-format-summary 142(defcustom icalendar-import-format-summary
@@ -247,7 +255,7 @@ Pass arguments REGEXP REP STRING FIXEDCASE LITERAL to
247INVALUE gives the current iCalendar element we are reading. 255INVALUE gives the current iCalendar element we are reading.
248INPARAMS gives the current parameters..... 256INPARAMS gives the current parameters.....
249This function calls itself recursively for each nested calendar element 257This function calls itself recursively for each nested calendar element
250it finds" 258it finds."
251 (let (element children line name params param param-name param-value 259 (let (element children line name params param param-name param-value
252 value 260 value
253 (continue t)) 261 (continue t))
@@ -923,89 +931,95 @@ entries. ENTRY-MAIN is the first line of the diary entry."
923 (error "Could not parse entry"))) 931 (error "Could not parse entry")))
924 932
925(defun icalendar--parse-summary-and-rest (summary-and-rest) 933(defun icalendar--parse-summary-and-rest (summary-and-rest)
926 "Parse SUMMARY-AND-REST from a diary to fill iCalendar properties." 934 "Parse SUMMARY-AND-REST from a diary to fill iCalendar properties.
935Returns an alist."
927 (save-match-data 936 (save-match-data
928 (let* ((s icalendar-import-format) 937 (if (functionp icalendar-import-format)
929 (p-cla (or (string-match "%c" icalendar-import-format) -1)) 938 ;; can't do anything
930 (p-des (or (string-match "%d" icalendar-import-format) -1)) 939 nil
931 (p-loc (or (string-match "%l" icalendar-import-format) -1)) 940 ;; split summary-and-rest
932 (p-org (or (string-match "%o" icalendar-import-format) -1)) 941 (let* ((s icalendar-import-format)
933 (p-sum (or (string-match "%s" icalendar-import-format) -1)) 942 (p-cla (or (string-match "%c" icalendar-import-format) -1))
934 (p-sta (or (string-match "%t" icalendar-import-format) -1)) 943 (p-des (or (string-match "%d" icalendar-import-format) -1))
935 (p-url (or (string-match "%u" icalendar-import-format) -1)) 944 (p-loc (or (string-match "%l" icalendar-import-format) -1))
936 (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url) '<)) 945 (p-org (or (string-match "%o" icalendar-import-format) -1))
937 pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url) 946 (p-sum (or (string-match "%s" icalendar-import-format) -1))
938 (dotimes (i (length p-list)) 947 (p-sta (or (string-match "%t" icalendar-import-format) -1))
939 (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla)) 948 (p-url (or (string-match "%u" icalendar-import-format) -1))
940 (setq pos-cla (+ 2 (* 2 i)))) 949 (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url) '<))
941 ((and (>= p-des 0) (= (nth i p-list) p-des)) 950 pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url)
942 (setq pos-des (+ 2 (* 2 i)))) 951 (dotimes (i (length p-list))
943 ((and (>= p-loc 0) (= (nth i p-list) p-loc)) 952 (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla))
944 (setq pos-loc (+ 2 (* 2 i)))) 953 (setq pos-cla (+ 2 (* 2 i))))
945 ((and (>= p-org 0) (= (nth i p-list) p-org)) 954 ((and (>= p-des 0) (= (nth i p-list) p-des))
946 (setq pos-org (+ 2 (* 2 i)))) 955 (setq pos-des (+ 2 (* 2 i))))
947 ((and (>= p-sta 0) (= (nth i p-list) p-sta)) 956 ((and (>= p-loc 0) (= (nth i p-list) p-loc))
948 (setq pos-sta (+ 2 (* 2 i)))) 957 (setq pos-loc (+ 2 (* 2 i))))
949 ((and (>= p-sum 0) (= (nth i p-list) p-sum)) 958 ((and (>= p-org 0) (= (nth i p-list) p-org))
950 (setq pos-sum (+ 2 (* 2 i)))) 959 (setq pos-org (+ 2 (* 2 i))))
951 ((and (>= p-url 0) (= (nth i p-list) p-url)) 960 ((and (>= p-sta 0) (= (nth i p-list) p-sta))
952 (setq pos-url (+ 2 (* 2 i)))))) 961 (setq pos-sta (+ 2 (* 2 i))))
953 (mapc (lambda (ij) 962 ((and (>= p-sum 0) (= (nth i p-list) p-sum))
954 (setq s (icalendar--rris (car ij) (cadr ij) s t t))) 963 (setq pos-sum (+ 2 (* 2 i))))
955 (list 964 ((and (>= p-url 0) (= (nth i p-list) p-url))
956 ;; summary must be first! because of %s 965 (setq pos-url (+ 2 (* 2 i))))))
957 (list "%s" 966 (mapc (lambda (ij)
958 (concat "\\(" icalendar-import-format-summary "\\)?")) 967 (setq s (icalendar--rris (car ij) (cadr ij) s t t)))
959 (list "%c" 968 (list
960 (concat "\\(" icalendar-import-format-class "\\)?")) 969 ;; summary must be first! because of %s
961 (list "%d" 970 (list "%s"
962 (concat "\\(" icalendar-import-format-description "\\)?")) 971 (concat "\\(" icalendar-import-format-summary "\\)??"))
963 (list "%l" 972 (list "%c"
964 (concat "\\(" icalendar-import-format-location "\\)?")) 973 (concat "\\(" icalendar-import-format-class "\\)??"))
965 (list "%o" 974 (list "%d"
966 (concat "\\(" icalendar-import-format-organizer "\\)?")) 975 (concat "\\(" icalendar-import-format-description "\\)??"))
967 (list "%t" 976 (list "%l"
968 (concat "\\(" icalendar-import-format-status "\\)?")) 977 (concat "\\(" icalendar-import-format-location "\\)??"))
969 (list "%u" 978 (list "%o"
970 (concat "\\(" icalendar-import-format-url "\\)?")))) 979 (concat "\\(" icalendar-import-format-organizer "\\)??"))
971 (setq s (concat (icalendar--rris "%s" "\\(.*\\)" s nil t) " ")) 980 (list "%t"
972 (if (string-match s summary-and-rest) 981 (concat "\\(" icalendar-import-format-status "\\)??"))
973 (let (cla des loc org sta sum url) 982 (list "%u"
974 (if (and pos-sum (match-beginning pos-sum)) 983 (concat "\\(" icalendar-import-format-url "\\)??"))))
975 (setq sum (substring summary-and-rest 984 (setq s (concat "^" (icalendar--rris "%s" "\\(.*?\\)" s nil t)
976 (match-beginning pos-sum) 985 " $"))
977 (match-end pos-sum)))) 986 (if (string-match s summary-and-rest)
978 (if (and pos-cla (match-beginning pos-cla)) 987 (let (cla des loc org sta sum url)
979 (setq cla (substring summary-and-rest 988 (if (and pos-sum (match-beginning pos-sum))
980 (match-beginning pos-cla) 989 (setq sum (substring summary-and-rest
981 (match-end pos-cla)))) 990 (match-beginning pos-sum)
982 (if (and pos-des (match-beginning pos-des)) 991 (match-end pos-sum))))
983 (setq des (substring summary-and-rest 992 (if (and pos-cla (match-beginning pos-cla))
984 (match-beginning pos-des) 993 (setq cla (substring summary-and-rest
985 (match-end pos-des)))) 994 (match-beginning pos-cla)
986 (if (and pos-loc (match-beginning pos-loc)) 995 (match-end pos-cla))))
987 (setq loc (substring summary-and-rest 996 (if (and pos-des (match-beginning pos-des))
988 (match-beginning pos-loc) 997 (setq des (substring summary-and-rest
989 (match-end pos-loc)))) 998 (match-beginning pos-des)
990 (if (and pos-org (match-beginning pos-org)) 999 (match-end pos-des))))
991 (setq org (substring summary-and-rest 1000 (if (and pos-loc (match-beginning pos-loc))
992 (match-beginning pos-org) 1001 (setq loc (substring summary-and-rest
993 (match-end pos-org)))) 1002 (match-beginning pos-loc)
994 (if (and pos-sta (match-beginning pos-sta)) 1003 (match-end pos-loc))))
995 (setq sta (substring summary-and-rest 1004 (if (and pos-org (match-beginning pos-org))
996 (match-beginning pos-sta) 1005 (setq org (substring summary-and-rest
997 (match-end pos-sta)))) 1006 (match-beginning pos-org)
998 (if (and pos-url (match-beginning pos-url)) 1007 (match-end pos-org))))
999 (setq url (substring summary-and-rest 1008 (if (and pos-sta (match-beginning pos-sta))
1000 (match-beginning pos-url) 1009 (setq sta (substring summary-and-rest
1001 (match-end pos-url)))) 1010 (match-beginning pos-sta)
1002 (list (if cla (cons 'cla cla) nil) 1011 (match-end pos-sta))))
1003 (if des (cons 'des des) nil) 1012 (if (and pos-url (match-beginning pos-url))
1004 (if loc (cons 'loc loc) nil) 1013 (setq url (substring summary-and-rest
1005 (if org (cons 'org org) nil) 1014 (match-beginning pos-url)
1006 (if sta (cons 'sta sta) nil) 1015 (match-end pos-url))))
1007 ;;(if sum (cons 'sum sum) nil) 1016 (list (if cla (cons 'cla cla) nil)
1008 (if url (cons 'url url) nil))))))) 1017 (if des (cons 'des des) nil)
1018 (if loc (cons 'loc loc) nil)
1019 (if org (cons 'org org) nil)
1020 (if sta (cons 'sta sta) nil)
1021 ;;(if sum (cons 'sum sum) nil)
1022 (if url (cons 'url url) nil))))))))
1009 1023
1010;; subroutines for icalendar-export-region 1024;; subroutines for icalendar-export-region
1011(defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) 1025(defun icalendar--convert-ordinary-to-ical (nonmarker entry-main)
@@ -1600,7 +1614,9 @@ buffer `*icalendar-errors*'."
1600 1614
1601(defun icalendar--format-ical-event (event) 1615(defun icalendar--format-ical-event (event)
1602 "Create a string representation of an iCalendar EVENT." 1616 "Create a string representation of an iCalendar EVENT."
1603 (let ((string icalendar-import-format) 1617 (if (functionp icalendar-import-format)
1618 (funcall icalendar-import-format event)
1619 (let ((string icalendar-import-format)
1604 (conversion-list 1620 (conversion-list
1605 '(("%c" CLASS icalendar-import-format-class) 1621 '(("%c" CLASS icalendar-import-format-class)
1606 ("%d" DESCRIPTION icalendar-import-format-description) 1622 ("%d" DESCRIPTION icalendar-import-format-description)
@@ -1628,7 +1644,7 @@ buffer `*icalendar-errors*'."
1628 string 1644 string
1629 t t)))) 1645 t t))))
1630 conversion-list) 1646 conversion-list)
1631 string)) 1647 string)))
1632 1648
1633(defun icalendar--convert-ical-to-diary (ical-list diary-file 1649(defun icalendar--convert-ical-to-diary (ical-list diary-file
1634 &optional do-not-ask 1650 &optional do-not-ask
@@ -2044,6 +2060,21 @@ the entry."
2044 ;; return diary-file in case it has been changed interactively 2060 ;; return diary-file in case it has been changed interactively
2045 diary-file) 2061 diary-file)
2046 2062
2063;; ======================================================================
2064;; Examples
2065;; ======================================================================
2066(defun icalendar-import-format-sample (event)
2067 "Example function for formatting an icalendar EVENT."
2068 (format (concat "SUMMARY=`%s' DESCRIPTION=`%s' LOCATION=`%s' ORGANIZER=`%s' "
2069 "STATUS=`%s' URL=`%s' CLASS=`%s'")
2070 (or (icalendar--get-event-property event 'SUMMARY) "")
2071 (or (icalendar--get-event-property event 'DESCRIPTION) "")
2072 (or (icalendar--get-event-property event 'LOCATION) "")
2073 (or (icalendar--get-event-property event 'ORGANIZER) "")
2074 (or (icalendar--get-event-property event 'STATUS) "")
2075 (or (icalendar--get-event-property event 'URL) "")
2076 (or (icalendar--get-event-property event 'CLASS) "")))
2077
2047(provide 'icalendar) 2078(provide 'icalendar)
2048 2079
2049;; arch-tag: 74fdbe8e-0451-4e38-bb61-4416e822f4fc 2080;; arch-tag: 74fdbe8e-0451-4e38-bb61-4416e822f4fc