emacs/lib/ics2org.el

48 lines
2.2 KiB
EmacsLisp
Raw Normal View History

;;; ics2org.el -- ics2org -*- lexical-binding: t -*-
;;; Commentary:
;;; Inspired by / adapted from `fosdem-ics-to-org-list', from
;;; https://geeksocket.in/posts/elisp-ics-org-mode-list/
;;; Original Code:
;;; (defun fosdem-ics-to-org-list ()
;;; "Iterate over the VEVENT entries and create an Org list"
;;; (interactive)
;;; (let (talks-list)
;;; (setq talks-list
;;; (concat
;;; "* FOSDEM talks [/]\n"
;;; (cl-loop while (re-search-forward "BEGIN:VEVENT" nil t) concat
;;; (let (start-time end-time summary url duration duration-minutes)
;;; (re-search-forward "DTSTART:\\(.*\\)")
;;; (setq start-time (match-string 1))
;;; (re-search-forward "DTEND:\\(.*\\)")
;;; (setq end-time (match-string 1))
;;; (re-search-forward "SUMMARY:\\(.*\\)")
;;; (setq summary (match-string 1))
;;; (re-search-forward "URL:\\(.*\\)")
;;; (setq url (match-string 1))
;;; (setq duration (time-subtract
;;; (parse-iso8601-time-string end-time)
;;; (parse-iso8601-time-string start-time)))
;;; (setq duration-minutes (/ duration 60))
;;; (format "- [ ] [[%s][%s]] (%sm)\n" url summary duration-minutes)))))
;;; (with-current-buffer (generate-new-buffer "FOSDEM")
;;; (insert talks-list)
;;; (org-mode)
;;; (org-update-statistics-cookies (point)))))
;;; Code:
(defun ics2org (filename)
"Convert ICS file `FILENAME' to Org event format and insert at point."
(interactive)
(if (not (file-exists-p filename))
(error "File %s not found" filename))
(require 'gnus-icalendar)
(find-file filename)
(with-current-buffer "*scratch*"
(let ((event (gnus-icalendar-event-from-buffer (find-buffer-visiting filename))))
(insert (format "* %s\n\n" (gnus-icalendar--format-summary-line (gnus-icalendar-event:summary event)
(gnus-icalendar-event:location event))))))
)
(provide 'ics2org)
;;; ics2org.el ends here