Experimenting with gnus-icalendar functions for ics2org.el
This commit is contained in:
parent
8bc691084c
commit
636ebd2a1c
|
@ -33,37 +33,15 @@
|
||||||
(defun ics2org (filename)
|
(defun ics2org (filename)
|
||||||
"Convert ICS file `FILENAME' to Org event format and insert at point."
|
"Convert ICS file `FILENAME' to Org event format and insert at point."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let (output-format
|
|
||||||
event-start
|
|
||||||
event-end
|
|
||||||
event-summary)
|
|
||||||
(if (not (file-exists-p filename))
|
(if (not (file-exists-p filename))
|
||||||
(error "File %s not found" filename))
|
(error "File %s not found" filename))
|
||||||
(progn
|
(require 'gnus-icalendar)
|
||||||
(find-file filename)
|
(find-file filename)
|
||||||
;; Find start time
|
(with-current-buffer "*scratch*"
|
||||||
(goto-char (point-min))
|
(let ((event (gnus-icalendar-event-from-buffer (find-buffer-visiting filename))))
|
||||||
(re-search-forward "DTSTART:\\(.*\\)")
|
(insert (format "* %s\n\n" (gnus-icalendar--format-summary-line (gnus-icalendar-event:summary event)
|
||||||
(setq event-start (date-to-time (match-string 1)))
|
(gnus-icalendar-event:location event))))))
|
||||||
;; Find end time
|
)
|
||||||
(goto-char (point-min))
|
|
||||||
(re-search-forward "DTEND:\\(.*\\)")
|
|
||||||
(setq event-end (date-to-time (match-string 1)))
|
|
||||||
;; Get event summary / title
|
|
||||||
(goto-char (point-min))
|
|
||||||
(re-search-forward "SUMMARY:\\(.*\\)")
|
|
||||||
(setq event-summary (match-string 1))
|
|
||||||
(previous-buffer))
|
|
||||||
;; Set a default `output-format', but replace with
|
|
||||||
;; `org-time-stamp-format' if available
|
|
||||||
(setq output-format "<%Y-%m-%d %a %H:%M>")
|
|
||||||
(if (fboundp 'org-time-stamp-format)
|
|
||||||
(setq output-format (org-time-stamp-format t nil)))
|
|
||||||
;; Return a formatted `org-mode' entry using parsed data
|
|
||||||
(format "* %s\n%s--%s\n"
|
|
||||||
event-summary
|
|
||||||
(format-time-string output-format event-start)
|
|
||||||
(format-time-string output-format event-end))))
|
|
||||||
|
|
||||||
(provide 'ics2org)
|
(provide 'ics2org)
|
||||||
;;; ics2org.el ends here
|
;;; ics2org.el ends here
|
||||||
|
|
Loading…
Reference in a new issue