aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorUlf Jasper2012-05-29 21:42:49 +0200
committerUlf Jasper2012-05-29 21:42:49 +0200
commit6dbaa1c769c3a0464ec72e4224cbd76c0356a2bf (patch)
tree4246e6205aa14095463e01d7e93724f4f973dd63 /lisp
parent471fe23dc58361ecad3679a3a57a9f7d949e34d2 (diff)
downloademacs-6dbaa1c769c3a0464ec72e4224cbd76c0356a2bf.tar.gz
emacs-6dbaa1c769c3a0464ec72e4224cbd76c0356a2bf.zip
icalendar-tests: Fix Bug#11525 -- Add icalendar-import-format-uid
2012-05-29 Ulf Jasper <ulf.jasper@web.de> * calendar/icalendar.el (icalendar-export-region): Export UID properly. 2012-05-29 Leo Liu <sdl.web@gmail.com> * calendar/icalendar.el (icalendar-import-format): Add `icalendar-import-format-uid' (Bug#11525). (icalendar-import-format-uid): New. (icalendar--parse-summary-and-rest, icalendar--format-ical-event): Export UID.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/calendar/icalendar.el50
2 files changed, 50 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 83d3f3e4677..b31cc2cef5f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12012-05-29 Ulf Jasper <ulf.jasper@web.de>
2
3 * calendar/icalendar.el
4 (icalendar-export-region): Export UID properly.
5
62012-05-29 Leo <sdl.web@gmail.com>
7 * calendar/icalendar.el (icalendar-import-format): Add
8 `icalendar-import-format-uid' (Bug#11525).
9 (icalendar-import-format-uid): New.
10 (icalendar--parse-summary-and-rest, icalendar--format-ical-event):
11 Export UID.
12
12012-05-29 Stefan Monnier <monnier@iro.umontreal.ca> 132012-05-29 Stefan Monnier <monnier@iro.umontreal.ca>
2 14
3 * emacs-lisp/pcase.el (pcase--expand): Accept different sets of vars in 15 * emacs-lisp/pcase.el (pcase--expand): Accept different sets of vars in
diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el
index f1549ec20b1..5dc687d001b 100644
--- a/lisp/calendar/icalendar.el
+++ b/lisp/calendar/icalendar.el
@@ -130,6 +130,7 @@ In case of a formatting STRING the following specifiers can be used:
130%s Summary, see `icalendar-import-format-summary' 130%s Summary, see `icalendar-import-format-summary'
131%t Status, see `icalendar-import-format-status' 131%t Status, see `icalendar-import-format-status'
132%u URL, see `icalendar-import-format-url' 132%u URL, see `icalendar-import-format-url'
133%U UID, see `icalendar-import-format-uid'
133 134
134A formatting FUNCTION will be called with a VEVENT as its only 135A formatting FUNCTION will be called with a VEVENT as its only
135argument. It must return a string. See 136argument. It must return a string. See
@@ -179,6 +180,14 @@ the URL."
179 :type 'string 180 :type 'string
180 :group 'icalendar) 181 :group 'icalendar)
181 182
183(defcustom icalendar-import-format-uid
184 "\n UID: %s"
185 "Format string defining how the UID element is formatted.
186This applies only if the UID is not empty! `%s' is replaced by
187the UID."
188 :type 'string
189 :group 'icalendar)
190
182(defcustom icalendar-import-format-status 191(defcustom icalendar-import-format-status
183 "\n Status: %s" 192 "\n Status: %s"
184 "Format string defining how the status element is formatted. 193 "Format string defining how the status element is formatted.
@@ -1017,7 +1026,8 @@ FExport diary data into iCalendar file: ")
1017 (org (cdr (assoc 'org other-elements))) 1026 (org (cdr (assoc 'org other-elements)))
1018 (sta (cdr (assoc 'sta other-elements))) 1027 (sta (cdr (assoc 'sta other-elements)))
1019 (sum (cdr (assoc 'sum other-elements))) 1028 (sum (cdr (assoc 'sum other-elements)))
1020 (url (cdr (assoc 'url other-elements)))) 1029 (url (cdr (assoc 'url other-elements)))
1030 (uid (cdr (assoc 'uid other-elements))))
1021 (if cla 1031 (if cla
1022 (setq contents (concat contents "\nCLASS:" cla))) 1032 (setq contents (concat contents "\nCLASS:" cla)))
1023 (if des 1033 (if des
@@ -1031,10 +1041,12 @@ FExport diary data into iCalendar file: ")
1031 ;;(if sum 1041 ;;(if sum
1032 ;; (setq contents (concat contents "\nSUMMARY:" sum))) 1042 ;; (setq contents (concat contents "\nSUMMARY:" sum)))
1033 (if url 1043 (if url
1034 (setq contents (concat contents "\nURL:" url)))) 1044 (setq contents (concat contents "\nURL:" url)))
1035 1045
1036 (setq header (concat "\nBEGIN:VEVENT\nUID:" 1046 (setq header (concat "\nBEGIN:VEVENT\nUID:"
1037 (icalendar--create-uid entry-full contents))) 1047 (or uid
1048 (icalendar--create-uid entry-full
1049 contents)))))
1038 (setq result (concat result header contents "\nEND:VEVENT"))) 1050 (setq result (concat result header contents "\nEND:VEVENT")))
1039 ;; handle errors 1051 ;; handle errors
1040 (error 1052 (error
@@ -1098,7 +1110,8 @@ Returns an alist."
1098 ;; can't do anything 1110 ;; can't do anything
1099 nil 1111 nil
1100 ;; split summary-and-rest 1112 ;; split summary-and-rest
1101 (let* ((s icalendar-import-format) 1113 (let* ((case-fold-search nil)
1114 (s icalendar-import-format)
1102 (p-cla (or (string-match "%c" icalendar-import-format) -1)) 1115 (p-cla (or (string-match "%c" icalendar-import-format) -1))
1103 (p-des (or (string-match "%d" icalendar-import-format) -1)) 1116 (p-des (or (string-match "%d" icalendar-import-format) -1))
1104 (p-loc (or (string-match "%l" icalendar-import-format) -1)) 1117 (p-loc (or (string-match "%l" icalendar-import-format) -1))
@@ -1106,9 +1119,10 @@ Returns an alist."
1106 (p-sum (or (string-match "%s" icalendar-import-format) -1)) 1119 (p-sum (or (string-match "%s" icalendar-import-format) -1))
1107 (p-sta (or (string-match "%t" icalendar-import-format) -1)) 1120 (p-sta (or (string-match "%t" icalendar-import-format) -1))
1108 (p-url (or (string-match "%u" icalendar-import-format) -1)) 1121 (p-url (or (string-match "%u" icalendar-import-format) -1))
1109 (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url) '<)) 1122 (p-uid (or (string-match "%U" icalendar-import-format) -1))
1123 (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url p-uid) '<))
1110 (ct 0) 1124 (ct 0)
1111 pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url) 1125 pos-cla pos-des pos-loc pos-org pos-sta pos-sum pos-url pos-uid)
1112 (dotimes (i (length p-list)) 1126 (dotimes (i (length p-list))
1113 ;; Use 'ct' to keep track of current position in list 1127 ;; Use 'ct' to keep track of current position in list
1114 (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla)) 1128 (cond ((and (>= p-cla 0) (= (nth i p-list) p-cla))
@@ -1131,7 +1145,10 @@ Returns an alist."
1131 (setq pos-sum (* 2 ct))) 1145 (setq pos-sum (* 2 ct)))
1132 ((and (>= p-url 0) (= (nth i p-list) p-url)) 1146 ((and (>= p-url 0) (= (nth i p-list) p-url))
1133 (setq ct (+ ct 1)) 1147 (setq ct (+ ct 1))
1134 (setq pos-url (* 2 ct)))) ) 1148 (setq pos-url (* 2 ct)))
1149 ((and (>= p-uid 0) (= (nth i p-list) p-uid))
1150 (setq ct (+ ct 1))
1151 (setq pos-uid (* 2 ct)))) )
1135 (mapc (lambda (ij) 1152 (mapc (lambda (ij)
1136 (setq s (icalendar--rris (car ij) (cadr ij) s t t))) 1153 (setq s (icalendar--rris (car ij) (cadr ij) s t t)))
1137 (list 1154 (list
@@ -1149,13 +1166,15 @@ Returns an alist."
1149 (list "%t" 1166 (list "%t"
1150 (concat "\\(" icalendar-import-format-status "\\)??")) 1167 (concat "\\(" icalendar-import-format-status "\\)??"))
1151 (list "%u" 1168 (list "%u"
1152 (concat "\\(" icalendar-import-format-url "\\)??")))) 1169 (concat "\\(" icalendar-import-format-url "\\)??"))
1170 (list "%U"
1171 (concat "\\(" icalendar-import-format-uid "\\)??"))))
1153 ;; Need the \' regexp in order to detect multi-line items 1172 ;; Need the \' regexp in order to detect multi-line items
1154 (setq s (concat "\\`" 1173 (setq s (concat "\\`"
1155 (icalendar--rris "%s" "\\(.*?\\)" s nil t) 1174 (icalendar--rris "%s" "\\(.*?\\)" s nil t)
1156 "\\'")) 1175 "\\'"))
1157 (if (string-match s summary-and-rest) 1176 (if (string-match s summary-and-rest)
1158 (let (cla des loc org sta sum url) 1177 (let (cla des loc org sta sum url uid)
1159 (if (and pos-sum (match-beginning pos-sum)) 1178 (if (and pos-sum (match-beginning pos-sum))
1160 (setq sum (substring summary-and-rest 1179 (setq sum (substring summary-and-rest
1161 (match-beginning pos-sum) 1180 (match-beginning pos-sum)
@@ -1184,13 +1203,18 @@ Returns an alist."
1184 (setq url (substring summary-and-rest 1203 (setq url (substring summary-and-rest
1185 (match-beginning pos-url) 1204 (match-beginning pos-url)
1186 (match-end pos-url)))) 1205 (match-end pos-url))))
1206 (if (and pos-uid (match-beginning pos-uid))
1207 (setq uid (substring summary-and-rest
1208 (match-beginning pos-uid)
1209 (match-end pos-uid))))
1187 (list (if cla (cons 'cla cla) nil) 1210 (list (if cla (cons 'cla cla) nil)
1188 (if des (cons 'des des) nil) 1211 (if des (cons 'des des) nil)
1189 (if loc (cons 'loc loc) nil) 1212 (if loc (cons 'loc loc) nil)
1190 (if org (cons 'org org) nil) 1213 (if org (cons 'org org) nil)
1191 (if sta (cons 'sta sta) nil) 1214 (if sta (cons 'sta sta) nil)
1192 ;;(if sum (cons 'sum sum) nil) 1215 ;;(if sum (cons 'sum sum) nil)
1193 (if url (cons 'url url) nil)))))))) 1216 (if url (cons 'url url) nil)
1217 (if uid (cons 'uid uid) nil))))))))
1194 1218
1195;; subroutines for icalendar-export-region 1219;; subroutines for icalendar-export-region
1196(defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) 1220(defun icalendar--convert-ordinary-to-ical (nonmarker entry-main)
@@ -1864,6 +1888,7 @@ buffer `*icalendar-errors*'."
1864 (if (functionp icalendar-import-format) 1888 (if (functionp icalendar-import-format)
1865 (funcall icalendar-import-format event) 1889 (funcall icalendar-import-format event)
1866 (let ((string icalendar-import-format) 1890 (let ((string icalendar-import-format)
1891 (case-fold-search nil)
1867 (conversion-list 1892 (conversion-list
1868 '(("%c" CLASS icalendar-import-format-class) 1893 '(("%c" CLASS icalendar-import-format-class)
1869 ("%d" DESCRIPTION icalendar-import-format-description) 1894 ("%d" DESCRIPTION icalendar-import-format-description)
@@ -1871,7 +1896,8 @@ buffer `*icalendar-errors*'."
1871 ("%o" ORGANIZER icalendar-import-format-organizer) 1896 ("%o" ORGANIZER icalendar-import-format-organizer)
1872 ("%s" SUMMARY icalendar-import-format-summary) 1897 ("%s" SUMMARY icalendar-import-format-summary)
1873 ("%t" STATUS icalendar-import-format-status) 1898 ("%t" STATUS icalendar-import-format-status)
1874 ("%u" URL icalendar-import-format-url)))) 1899 ("%u" URL icalendar-import-format-url)
1900 ("%U" UID icalendar-import-format-uid))))
1875 ;; convert the specifiers in the format string 1901 ;; convert the specifiers in the format string
1876 (mapc (lambda (i) 1902 (mapc (lambda (i)
1877 (let* ((spec (car i)) 1903 (let* ((spec (car i))