Function: icalendar-import-buffer

icalendar-import-buffer is an autoloaded, interactive and byte-compiled function defined in icalendar.el.gz.

Signature

(icalendar-import-buffer &optional DIARY-FILENAME DO-NOT-ASK NON-MARKING)

Documentation

Extract iCalendar events from current buffer.

This function searches the current buffer for the first iCalendar object, reads it and adds all VEVENT elements to the diary DIARY-FILENAME.

It will ask for each appointment whether to add it to the diary unless DO-NOT-ASK is non-nil. When called interactively, DO-NOT-ASK is nil, so that you are asked for each event.

NON-MARKING determines whether diary events are created as non-marking.

Return code t means that importing worked well, return code nil means that an error has occurred. Error messages will be in the buffer *icalendar-errors*.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar.el.gz
;;;###autoload
(defun icalendar-import-buffer (&optional diary-filename do-not-ask
                                          non-marking)
  "Extract iCalendar events from current buffer.

This function searches the current buffer for the first iCalendar
object, reads it and adds all VEVENT elements to the diary
DIARY-FILENAME.

It will ask for each appointment whether to add it to the diary
unless DO-NOT-ASK is non-nil.  When called interactively,
DO-NOT-ASK is nil, so that you are asked for each event.

NON-MARKING determines whether diary events are created as
non-marking.

Return code t means that importing worked well, return code nil
means that an error has occurred.  Error messages will be in the
buffer `*icalendar-errors*'."
  (interactive)
  (save-current-buffer
    ;; prepare ical
    (message "Preparing iCalendar...")
    (set-buffer (icalendar--get-unfolded-buffer (current-buffer)))
    (goto-char (point-min))
    (message "Preparing iCalendar...done")
    (if (re-search-forward "^BEGIN:VCALENDAR\\s-*$" nil t)
        (let (ical-contents ical-errors)
          ;; read ical
          (message "Reading iCalendar...")
          (beginning-of-line)
          (setq ical-contents (icalendar--read-element nil nil))
          (message "Reading iCalendar...done")
          ;; convert ical
          (message "Converting iCalendar...")
          (setq ical-errors (icalendar--convert-ical-to-diary
                             ical-contents
                             diary-filename do-not-ask non-marking))
          (when diary-filename
            ;; save the diary file if it is visited already
            (let ((b (find-buffer-visiting diary-filename)))
              (when b
                (save-current-buffer
                  (set-buffer b)
                  (save-buffer)))))
          (message "Converting iCalendar...done")
          ;; return t if no error occurred
          (not ical-errors))
      (message
       "Current buffer does not contain iCalendar contents!")
      ;; return nil, i.e. import did not work
      nil)))