Function: gnus-icalendar--update-org-event

gnus-icalendar--update-org-event is a byte-compiled function defined in gnus-icalendar.el.gz.

Signature

(gnus-icalendar--update-org-event EVENT REPLY-STATUS &optional ORG-FILE)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-icalendar.el.gz
(defun gnus-icalendar--update-org-event (event reply-status &optional org-file)
  (let ((file (gnus-icalendar-find-org-event-file event org-file)))
    (when file
      (with-current-buffer (find-file-noselect file)
        (with-slots (uid summary description organizer location recur
                         participation-type req-participants opt-participants) event
          (let ((event-pos (org-find-entry-with-id uid)))
            (when event-pos
              (goto-char event-pos)

              ;; update the headline, keep todo, priority and tags, if any
              (save-excursion
                (let* ((priority (org-entry-get (point) "PRIORITY"))
                       (headline (delq nil (list
                                            (org-entry-get (point) "TODO")
                                            (when priority (format "[#%s]" priority))
                                            (gnus-icalendar--format-summary-line summary location)
                                            (org-entry-get (point) "TAGS")))))

                  (re-search-forward "^\\*+ " (line-end-position))
                  (delete-region (point) (line-end-position))
                  (insert (mapconcat #'identity headline " "))))

              ;; update props and description
              (let ((entry-end (org-entry-end-position))
                    (entry-outline-level (org-outline-level)))

                ;; delete body of the entry, leave org drawers intact
                (save-restriction
                  (org-narrow-to-element)
                  (goto-char entry-end)
                  (re-search-backward "^[\t ]*:END:")
                  (forward-line)
                  (delete-region (point) entry-end))

                ;; put new event description in the entry body
                (save-restriction
                  (narrow-to-region (point) (point))
                  (insert "\n"
                          (gnus-icalendar-event:org-timestamp event)
                          "\n\n"
                          (replace-regexp-in-string "[\n]+$" "\n"
                                                    (or description "No description"))
                          "\n")
                  (indent-region (point-min) (point-max) (1+ entry-outline-level))
                  (fill-region (point-min) (point-max)))

                ;; update entry properties
                (cl-labels
                    ((update-org-entry
		      (position property value)
		      (if (or (null value)
			      (string= value ""))
			  (org-entry-delete position property)
			(org-entry-put position property value))))

                  (update-org-entry event-pos "ORGANIZER" organizer)
                  (update-org-entry event-pos "LOCATION" location)
                  (update-org-entry event-pos "PARTICIPATION_TYPE"
				    (symbol-name participation-type))
                  (update-org-entry event-pos "REQ_PARTICIPANTS"
				    (gnus-icalendar--format-participant-list
				     req-participants))
                  (update-org-entry event-pos "OPT_PARTICIPANTS"
				    (gnus-icalendar--format-participant-list
				     opt-participants))
                  (update-org-entry event-pos "RRULE" recur)
                  (update-org-entry
		   event-pos "REPLY"
		   (if reply-status (capitalize (symbol-name reply-status))
		     "Not replied yet")))
                (save-buffer)))))))))