From 2f0ebbf9b431e75a04436a7920969dc8a6914665 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Mon, 24 Jun 2024 11:25:41 +0100 Subject: [PATCH] Add initial version of ics2org function Function parses an ICS file and returns formatted as an Org event, currently just prints to standard out, but will modify to insert to current buffer / buffer of choosing Move a couple of extra functions into lib directory with ics2org, to be a bit more organised --- init.el | 4 +- install.el | 2 +- lib/ics2org.el | 69 ++++++++++++++++++++++ mu4e-custom.el => lib/mu4e-custom.el | 0 package-config.el => lib/package-config.el | 0 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 lib/ics2org.el rename mu4e-custom.el => lib/mu4e-custom.el (100%) rename package-config.el => lib/package-config.el (100%) diff --git a/init.el b/init.el index 18b73c5..74b372d 100644 --- a/init.el +++ b/init.el @@ -7,7 +7,7 @@ (setopt warning-minimum-level :error) ;; Configure packages archives with priority -(load-file (locate-user-emacs-file "package-config.el")) +(load-file (locate-user-emacs-file "lib/package-config.el")) (setq custom-file (locate-user-emacs-file "custom.el")) (when (and custom-file @@ -1115,7 +1115,7 @@ Calls `project-remember-projects-under' for ~/Projects/" :custom (bbdb-file (locate-user-emacs-file "bbdb.gpg"))) -(load-file (locate-user-emacs-file "mu4e-custom.el")) +(load-file (locate-user-emacs-file "lib/mu4e-custom.el")) (use-package erc :commands erc-compute-nick diff --git a/install.el b/install.el index dbcfd6c..7df99b1 100644 --- a/install.el +++ b/install.el @@ -2,7 +2,7 @@ ;;; Commentary: ;;; Code: ;; Configure packages archives with priority -(load-file "package-config.el") +(load-file "lib/package-config.el") (package-refresh-contents) (setopt package-selected-packages '( diff --git a/lib/ics2org.el b/lib/ics2org.el new file mode 100644 index 0000000..797fe09 --- /dev/null +++ b/lib/ics2org.el @@ -0,0 +1,69 @@ +;;; 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) + (let (output-format + event-start + event-end + event-summary) + (if (not (file-exists-p filename)) + (error "File %s not found" filename)) + (progn + (find-file filename) + ;; Find start time + (goto-char (point-min)) + (re-search-forward "DTSTART:\\(.*\\)") + (setq event-start (date-to-time (match-string 1))) + ;; 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) +;;; ics2org.el ends here diff --git a/mu4e-custom.el b/lib/mu4e-custom.el similarity index 100% rename from mu4e-custom.el rename to lib/mu4e-custom.el diff --git a/package-config.el b/lib/package-config.el similarity index 100% rename from package-config.el rename to lib/package-config.el