]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/icalendar.el
Ibuffer: Mark buffers by content
[gnu-emacs] / lisp / calendar / icalendar.el
index bced4e20e023cb6c8a93a7446cbaa65212d33d9f..386c554c0687b149d43dda6c8dfd9913fee46116 100644 (file)
@@ -1,6 +1,6 @@
-;;; icalendar.el --- iCalendar implementation -*-coding: utf-8 -*-
+;;; icalendar.el --- iCalendar implementation
 
-;; Copyright (C) 2002-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2016 Free Software Foundation, Inc.
 
 ;; Author:         Ulf Jasper <ulf.jasper@web.de>
 ;; Created:        August 2002
@@ -261,7 +261,7 @@ If non-nil all sexp diary entries are enumerated for
 `icalendar-export-sexp-enumeration-days' days instead of
 translating into an icalendar equivalent.  This affects the
 following sexp diary entries: `diary-anniversary',
-`diary-cyclic', `diary-date', `diary-float',`diary-block'.  All
+`diary-cyclic', `diary-date', `diary-float', `diary-block'.  All
 other sexp entries are enumerated in any case."
   :version "25.1"
   :type 'boolean
@@ -321,18 +321,29 @@ other sexp entries are enumerated in any case."
   "Return a new buffer containing the unfolded contents of a buffer.
 Folding is the iCalendar way of wrapping long lines.  In the
 created buffer all occurrences of CR LF BLANK are replaced by the
-empty string.  Argument FOLDED-ICAL-BUFFER is the unfolded input
+empty string.  Argument FOLDED-ICAL-BUFFER is the folded input
 buffer."
   (let ((unfolded-buffer (get-buffer-create " *icalendar-work*")))
     (save-current-buffer
       (set-buffer unfolded-buffer)
       (erase-buffer)
       (insert-buffer-substring folded-ical-buffer)
+      (icalendar--clean-up-line-endings)
       (goto-char (point-min))
       (while (re-search-forward "\r?\n[ \t]" nil t)
         (replace-match "" nil nil)))
     unfolded-buffer))
 
+(defun icalendar--clean-up-line-endings ()
+  "Replace DOS- and MAC-like line endings with unix line endings.
+All occurrences of (CR LF) and (LF CF) are replaced with LF in
+the current buffer.  This is necessary in buffers which contain a
+mix of different line endings."
+  (save-excursion
+    (goto-char (point-min))
+    (while (re-search-forward "\r\n\\|\n\r" nil t)
+      (replace-match "\n" nil nil))))
+
 (defsubst icalendar--rris (regexp rep string &optional fixedcase literal)
   "Replace regular expression in string.
 Pass arguments REGEXP REP STRING FIXEDCASE LITERAL to
@@ -482,7 +493,7 @@ children."
     result))
 
 (defun icalendar--split-value (value-string)
-  "Split VALUE-STRING at ';='."
+  "Split VALUE-STRING at `;='."
   (let ((result '())
         param-name param-value)
     (when value-string
@@ -1118,10 +1129,10 @@ FExport diary data into iCalendar file: ")
            (setq found-error t)
            (save-current-buffer
              (set-buffer (get-buffer-create "*icalendar-errors*"))
-             (insert (format "Error in line %d -- %s: ‘%s’\n"
-                             (count-lines (point-min) (point))
-                             error-val
-                             entry-main))))))
+             (insert (format-message "Error in line %d -- %s: `%s'\n"
+                                     (count-lines (point-min) (point))
+                                     error-val
+                                     entry-main))))))
 
       ;; we're done, insert everything into the file
       (save-current-buffer
@@ -1296,8 +1307,8 @@ Returns an alist."
   "Return a VALARM block.
 Argument ADVANCE-TIME is a number giving the time when the alarm
 fires (minutes before the respective event).  Argument ALARM-SPEC
-is a list which must be one of '(audio), '(display) or
-'(email (ADDRESS1 ...)), see `icalendar-export-alarms'.  Argument
+is a list which must be one of (audio), (display) or
+(email (ADDRESS1 ...)), see `icalendar-export-alarms'.  Argument
 SUMMARY is a string which contains a short description for the
 alarm."
   (let* ((action (car alarm-spec))
@@ -1741,7 +1752,7 @@ entries.  ENTRY-MAIN is the first line of the diary entry."
           (when day
             (progn
               (icalendar--dmsg "diary-float %s" entry-main)
-              (error "Don't know if or how to implement day in ‘diary-float’")))
+              (error "Don't know if or how to implement day in `diary-float'")))
 
           (cons (concat
                  ;;Start today (yes this is an arbitrary choice):
@@ -1788,7 +1799,7 @@ entries.  ENTRY-MAIN is the first line of the diary entry."
                     entry-main)
       (progn
         (icalendar--dmsg "diary-date %s" entry-main)
-        (error "‘diary-date’ is not supported yet"))
+        (error "`diary-date' is not supported yet"))
     ;; no match
     nil))
 
@@ -2104,7 +2115,7 @@ written into the buffer `*icalendar-errors*'."
                  (rrule (icalendar--get-event-property e 'RRULE))
                  (rdate (icalendar--get-event-property e 'RDATE))
                  (duration (icalendar--get-event-property e 'DURATION)))
-            (icalendar--dmsg "%s: ‘%s’" start-d summary)
+            (icalendar--dmsg "%s: `%s'" start-d summary)
             ;; check whether start-time is missing
             (if  (and dtstart
                       (string=
@@ -2282,7 +2293,7 @@ END-T is the event's end time in diary format."
                                                    interval))))
                  )
                 (t
-                 (message "Cannot handle COUNT attribute for ‘%s’ events."
+                 (message "Cannot handle COUNT attribute for `%s' events."
                           frequency)))
           (setq until-conv (icalendar--datetime-to-diary-date until))
           (setq until-1-conv (icalendar--datetime-to-diary-date until-1))
@@ -2473,8 +2484,8 @@ SUMMARY is not nil it must be a string that gives the summary of the
 entry.  In this case the user will be asked whether he wants to insert
 the entry."
   (when (or (not summary)
-            (y-or-n-p (format "Add appointment for ‘%s’ to diary? "
-                              summary)))
+            (y-or-n-p (format-message "Add appointment for `%s' to diary? "
+                                      summary)))
     (when summary
       (setq non-marking
             (y-or-n-p (format "Make appointment non-marking? "))))