Function: diary-icalendar-import-buffer-to-buffer

diary-icalendar-import-buffer-to-buffer is a byte-compiled function defined in diary-icalendar.el.gz.

Signature

(diary-icalendar-import-buffer-to-buffer &optional ALL-NONMARKING)

Documentation

Format iCalendar data in current buffer as diary entries.

This function parses the first iCalendar VCALENDAR in the current buffer and formats its VEVENT, VJOURNAL, and VTODO components as diary entries. It returns a new buffer containing those diary entries. The caller should kill this buffer when it is no longer needed.

If ALL-NONMARKING is non-nil, all diary entries will be non-marking.

The list of components to import can be filtered by binding diary-icalendar-import-predicate. After each component is formatted as a diary entry, diary-icalendar-post-entry-format-hook is run in a (narrowed) buffer containing that entry. After all components have been formatted, diary-icalendar-post-calendar-format-hook is run in the (widened) buffer containing all the entries.

The formatting of imported entries depends on a number of user-customizable variables, including: diary-date-forms, calendar-date-style, calendar-date-display-form and customizations in the diary-icalendar group.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/diary-icalendar.el.gz
(defun di:import-buffer-to-buffer (&optional all-nonmarking)
  "Format iCalendar data in current buffer as diary entries.

This function parses the first iCalendar VCALENDAR in the current buffer
and formats its VEVENT, VJOURNAL, and VTODO components as diary entries.
It returns a new buffer containing those diary entries.  The caller
should kill this buffer when it is no longer needed.

If ALL-NONMARKING is non-nil, all diary entries will be non-marking.

The list of components to import can be filtered by binding
`diary-icalendar-import-predicate'.  After each component is formatted as
a diary entry, `diary-icalendar-post-entry-format-hook' is run in a (narrowed)
buffer containing that entry.  After all components have been formatted,
`diary-icalendar-post-calendar-format-hook' is run in the (widened) buffer
containing all the entries.

The formatting of imported entries depends on a number of
user-customizable variables, including: `diary-date-forms',
`calendar-date-style', `calendar-date-display-form' and customizations
in the `diary-icalendar' group."
  (unless (ical:contains-vcalendar-p (current-buffer))
    (di:signal-import-error (format "No VCALENDAR object in buffer %s"
                                    (buffer-name))))
  (save-excursion
    (goto-char (point-min))
    (let (vcalendar index)
      (ical:init-error-buffer)
      (let ((vcal/idx (ical:parse-and-index (current-buffer))))
        (when vcal/idx
          (setq vcalendar (car vcal/idx))
          (setq index (cadr vcal/idx))
          (let* ((import-buf (generate-new-buffer " *diary-import*"))
                 (to-import
                  (sort
                   (seq-filter
                    (lambda (c)
                      (and (or (ical:vevent-component-p c)
                               (ical:vjournal-component-p c)
                               (ical:vtodo-component-p c))
                           (funcall di:import-predicate c)))
                    (ical:ast-node-children vcalendar))
                  :lessp di:import-comparison-function
                  :in-place t))
                 ;; prevent point from being reset from window-point
                 ;; when narrowed buffer is displayed for confirmation:
                 (window-point-insertion-type t)
                 ;; position at start of each entry:
                 entry-start)

            (with-current-buffer import-buf
              (dlet ((ical-importing t)) ; inform skeletons we're importing
                (dolist (component to-import)
                  (setq entry-start (point))
                  (insert (di:format-entry component index all-nonmarking))
                  (with-restriction entry-start (point)
                    (save-excursion
                      (run-hooks 'di:post-entry-format-hook)))
                  (unless (bolp) (insert "\n"))))
              (save-excursion
                (run-hooks 'di:post-calendar-format-hook))
              import-buf)))))))