From 2d2cab9d97d3e84e5b7158181523fe2c5bbffe85 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 16 Apr 2023 17:06:41 -0500 Subject: uhhh --- lisp/ical2org.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lisp/ical2org.el (limited to 'lisp/ical2org.el') diff --git a/lisp/ical2org.el b/lisp/ical2org.el new file mode 100644 index 0000000..2716787 --- /dev/null +++ b/lisp/ical2org.el @@ -0,0 +1,56 @@ +;;; ical2org.el --- Run ical2org in Emacs -*- lexical-binding: t; -*- + +;;; Commentary: + +;; based on code from this reddit thread: +;; https://www.reddit.com/r/emacs/comments/8s1ion/ical2org_integrations/ +;; +;; see also: icalendar.org (converts to diary format, might be all I need) +;; +;; XXX: This code currently imports into gnus, which isn't what I want. + +;;; Code: + +(defun ical2org (&optional replace output-buffer) + "Run ical2org on contents of this buffer. +If REPLACE (interactive prefix argument), replace contents of the +buffer. If no REPLACE nor OUTPUT-BUFFER, output goes to +minibuffer." + (interactive "P") + (shell-command-on-region (point-min) (point-max) + "ical2org" + output-buffer + replace + "*ical2org errors*" + 'display-errors)) + +(defun ical2org-capture () + "Run `ical2org' on this buffer, then `org-capture' the result. +Leaves current buffer as-was afterwards." + (interactive) + (let ((buf (current-buffer)) + (ics (buffer-string))) + (ical2org 'replace) + (mark-whole-buffer) + (call-interactively #'org-capture) + (with-current-buffer buf + (delete-region (point-min) (point-max)) + (insert ics)))) + +(defun my-gnus-org-capture-icalendar () + "Capture any text/calendar invites with org." + (interactive) + (with-current-buffer gnus-article-buffer ;;; XXX + (save-excursion + (dolist (part gnus-article-mime-handle-alist) + (when (and (>= (length part) 3) + (listp (caddr part)) + (or (equal "application/ics" (caaddr part)) + (equal "text/calendar" (caaddr part)))) + (save-window-excursion + (gnus-mime-copy-part (cdr part)) + (ical2org-capture))))))) +(add-hook 'gnus-article-prepare-hook #'my-gnus-org-capture-icalendar) + +(provide 'ical2org) +;;; ical2org.el ends here -- cgit 1.4.1-21-gabe81