diff options
| author | Ulf Jasper | 2014-11-15 20:54:28 +0100 |
|---|---|---|
| committer | Ulf Jasper | 2014-11-16 17:38:09 +0100 |
| commit | 6f20cde0117a181159eed4a1992ed8c536d8ecce (patch) | |
| tree | dc8024e7872471585e17ab66354c416fb118cbbb | |
| parent | 0df06a3ac574ddd17cdf82c0f1f236711c768305 (diff) | |
| download | emacs-6f20cde0117a181159eed4a1992ed8c536d8ecce.tar.gz emacs-6f20cde0117a181159eed4a1992ed8c536d8ecce.zip | |
alarm export, first step
| -rw-r--r-- | lisp/calendar/icalendar.el | 68 | ||||
| -rw-r--r-- | test/automated/icalendar-tests.el | 15 |
2 files changed, 60 insertions, 23 deletions
diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index cdda8f0fba2..e00976da349 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el | |||
| @@ -270,28 +270,22 @@ other sexp entries are enumerated in any case." | |||
| 270 | (defcustom icalendar-export-alarms | 270 | (defcustom icalendar-export-alarms |
| 271 | nil | 271 | nil |
| 272 | "Determine if and how alarms are included in exported diary events. | 272 | "Determine if and how alarms are included in exported diary events. |
| 273 | FIXME | 273 | FIXME" |
| 274 | ... appt-display-format | ||
| 275 | ... appt-audible | ||
| 276 | .... appt-message-warning-time | ||
| 277 | ... appt-warning-time-regexp | ||
| 278 | " | ||
| 279 | :version "25.1" | 274 | :version "25.1" |
| 280 | :type '(choice (const :tag "Do not include alarms in export" nil) | 275 | :type '(choice (const :tag "Do not include alarms in export" |
| 281 | (const :tag "Apply emacs defaults FIXME" 'default) | 276 | nil) |
| 282 | (list :tag "Create alarms in exported diary entries" | 277 | (list :tag "Create alarms in exported diary entries" |
| 283 | (integer :tag "Advance time (minutes)" | 278 | (integer :tag "Advance time (minutes)" |
| 284 | ;; FIXME | 279 | :value 10) |
| 285 | :value appt-message-warning-time) | 280 | (set :tag "Alarm type" |
| 286 | (choice :tag "Alarm type" | 281 | (list :tag "Audio" |
| 287 | (list :tag "Audio" | 282 | (const audio :tag "Audio")) |
| 288 | (string :tag "Audio file")) | 283 | (list :tag "Display" |
| 289 | (cons :tag "Display" | 284 | (const display :tag "Display")) |
| 290 | (string :tag "Description")) | 285 | (list :tag "Email" |
| 291 | (list :tag "Email" | 286 | (const email) |
| 292 | (string :tag "Description") | 287 | (repeat :tag "Attendees" |
| 293 | (string :tag "Summary") | 288 | (string :tag "Email")))))) |
| 294 | (string :tag "Attendees"))))) | ||
| 295 | :group 'icalendar) | 289 | :group 'icalendar) |
| 296 | 290 | ||
| 297 | 291 | ||
| @@ -1055,6 +1049,7 @@ FExport diary data into iCalendar file: ") | |||
| 1055 | (header "") | 1049 | (header "") |
| 1056 | (contents-n-summary) | 1050 | (contents-n-summary) |
| 1057 | (contents) | 1051 | (contents) |
| 1052 | (alarm) | ||
| 1058 | (found-error nil) | 1053 | (found-error nil) |
| 1059 | (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol) | 1054 | (nonmarker (concat "^" (regexp-quote diary-nonmarking-symbol) |
| 1060 | "?")) | 1055 | "?")) |
| @@ -1117,8 +1112,10 @@ FExport diary data into iCalendar file: ") | |||
| 1117 | (setq header (concat "\nBEGIN:VEVENT\nUID:" | 1112 | (setq header (concat "\nBEGIN:VEVENT\nUID:" |
| 1118 | (or uid | 1113 | (or uid |
| 1119 | (icalendar--create-uid | 1114 | (icalendar--create-uid |
| 1120 | entry-full contents))))) | 1115 | entry-full contents)))) |
| 1121 | (setq result (concat result header contents | 1116 | (setq alarm (icalendar--create-ical-alarm |
| 1117 | (car contents-n-summary)))) | ||
| 1118 | (setq result (concat result header contents alarm | ||
| 1122 | "\nEND:VEVENT"))) | 1119 | "\nEND:VEVENT"))) |
| 1123 | (if (consp cns-cons-or-list) | 1120 | (if (consp cns-cons-or-list) |
| 1124 | (list cns-cons-or-list) | 1121 | (list cns-cons-or-list) |
| @@ -1293,6 +1290,35 @@ Returns an alist." | |||
| 1293 | (if url (cons 'url url) nil) | 1290 | (if url (cons 'url url) nil) |
| 1294 | (if uid (cons 'uid uid) nil)))))))) | 1291 | (if uid (cons 'uid uid) nil)))))))) |
| 1295 | 1292 | ||
| 1293 | (defun icalendar--create-ical-alarm (summary) | ||
| 1294 | (when icalendar-export-alarms | ||
| 1295 | (let* ((advance-time (car icalendar-export-alarms)) | ||
| 1296 | (alarm-specs (cadr icalendar-export-alarms)) | ||
| 1297 | (fun (lambda (spec) | ||
| 1298 | (icalendar--do-create-ical-alarm advance-time spec summary)))) | ||
| 1299 | (mapconcat fun alarm-specs "\n")))) | ||
| 1300 | |||
| 1301 | (defun icalendar--do-create-ical-alarm (advance-time alarm-spec summary) | ||
| 1302 | (let* ((action (car alarm-spec)) | ||
| 1303 | (act (format "ACTION:%s\n" | ||
| 1304 | (cdr (assoc action '((audio . "AUDIO") | ||
| 1305 | (display . "DISPLAY") | ||
| 1306 | (email . "EMAIL")))))) | ||
| 1307 | (tri (format "TRIGGER:-PT%dM\n" advance-time)) | ||
| 1308 | (des (if (memq action '(display email)) | ||
| 1309 | (format "DESCRIPTION:%s\n" summary) | ||
| 1310 | "")) | ||
| 1311 | (sum (if (eq action 'email) | ||
| 1312 | (format "SUMMARY:%s\n" summary) | ||
| 1313 | "")) | ||
| 1314 | (att (if (eq action 'email) | ||
| 1315 | (mapconcat (lambda (i) | ||
| 1316 | (format "ATTENDEE:MAILTO:%s\n" i)) | ||
| 1317 | (cadr alarm-spec) "") | ||
| 1318 | ""))) | ||
| 1319 | |||
| 1320 | (concat "BEGIN:VALARM\n" act tri des sum att "END:VALARM"))) | ||
| 1321 | |||
| 1296 | ;; subroutines for icalendar-export-region | 1322 | ;; subroutines for icalendar-export-region |
| 1297 | (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) | 1323 | (defun icalendar--convert-ordinary-to-ical (nonmarker entry-main) |
| 1298 | "Convert \"ordinary\" diary entry to iCalendar format. | 1324 | "Convert \"ordinary\" diary entry to iCalendar format. |
diff --git a/test/automated/icalendar-tests.el b/test/automated/icalendar-tests.el index 23afb14792d..3e2fecff1cd 100644 --- a/test/automated/icalendar-tests.el +++ b/test/automated/icalendar-tests.el | |||
| @@ -503,6 +503,15 @@ END:VEVENT | |||
| 503 | ;; restore time-zone even if something went terribly wrong | 503 | ;; restore time-zone even if something went terribly wrong |
| 504 | (setenv "TZ" tz))) ) | 504 | (setenv "TZ" tz))) ) |
| 505 | 505 | ||
| 506 | (ert-deftest icalendar--create-ical-alarm () | ||
| 507 | "Test `icalendar--create-ical-alarms'." | ||
| 508 | (let ((icalendar-export-alarms)) | ||
| 509 | ;; testcase: no alarms | ||
| 510 | (setq icalendar-export-alarm nil) | ||
| 511 | (should (equal nil | ||
| 512 | (icalendar--create-ical-alarm "sumsum"))))) | ||
| 513 | |||
| 514 | |||
| 506 | ;; ====================================================================== | 515 | ;; ====================================================================== |
| 507 | ;; Export tests | 516 | ;; Export tests |
| 508 | ;; ====================================================================== | 517 | ;; ====================================================================== |
| @@ -519,7 +528,8 @@ European style input data must use german month names. American | |||
| 519 | and ISO style input data must use english month names." | 528 | and ISO style input data must use english month names." |
| 520 | (let ((tz (getenv "TZ")) | 529 | (let ((tz (getenv "TZ")) |
| 521 | (calendar-date-style 'iso) | 530 | (calendar-date-style 'iso) |
| 522 | (icalendar-recurring-start-year 2000)) | 531 | (icalendar-recurring-start-year 2000) |
| 532 | (icalendar-export-alarms nil)) | ||
| 523 | (unwind-protect | 533 | (unwind-protect |
| 524 | (progn | 534 | (progn |
| 525 | ;;; (message "Current time zone: %s" (current-time-zone)) | 535 | ;;; (message "Current time zone: %s" (current-time-zone)) |
| @@ -1286,7 +1296,8 @@ Argument INPUT icalendar event string." | |||
| 1286 | (icalendar-import-format-status "\n Status: %s") | 1296 | (icalendar-import-format-status "\n Status: %s") |
| 1287 | (icalendar-import-format-url "\n URL: %s") | 1297 | (icalendar-import-format-url "\n URL: %s") |
| 1288 | (icalendar-import-format-class "\n Class: %s") | 1298 | (icalendar-import-format-class "\n Class: %s") |
| 1289 | (icalendar-import-format-class "\n UID: %s")) | 1299 | (icalendar-import-format-class "\n UID: %s") |
| 1300 | (icalendar-export-alarms nil)) | ||
| 1290 | (dolist (calendar-date-style '(iso european american)) | 1301 | (dolist (calendar-date-style '(iso european american)) |
| 1291 | (icalendar-tests--do-test-cycle))))) | 1302 | (icalendar-tests--do-test-cycle))))) |
| 1292 | 1303 | ||