all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Ical import in Emacs 27.1 core packages
@ 2020-08-13 13:45 Russell Adams
  0 siblings, 0 replies; only message in thread
From: Russell Adams @ 2020-08-13 13:45 UTC (permalink / raw)
  To: emacs-orgmode

Hello Org-ers!

I've just upgraded to Emacs 27.1 and the latest Org
(9.3.7-18-g093b47-elpa). While reviewing my init.el I found I was
still depending on org-import-icalendar.el to import ics files.

The link on Worg for this file is broken, and I could not find a good
source. It's not in ELPA or MELPA, so I felt it was a dead end.

Instead I discovered that Emacs Gnus already has an icalendar importer
which includes some Org functions! I'm not sure when they were
introduced, but I wanted to share because it's a built-in.

In my init.el:

#+begin_src lisp
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; Ical

  ;; Import ical files
  (require 'gnus-icalendar)
  (add-to-list 'org-capture-templates
               '("#" "Ical capture target" plain
                 (file "~/doc/OrgFiles/Agenda.org")
                 "%i"
                 :immediate-finish t :empty-lines 1))
  (setq gnus-icalendar-org-template-key "#")

  (defun rla-import-ical-to-org-capture (filename)
    (with-temp-buffer
      (insert-file-contents filename)
      (gnus-icalendar:org-event-save
       (gnus-icalendar-event-from-buffer (current-buffer))
       nil)))
#+end_src

The key is to have a predefined org-capture template created for
Gnus. There is a function to create one for you, but I preferred to
make one by hand which is just a plain Org file with each new event
appended to the end of the file. The Agenda.org file is also in my
agenda list.

Then I added a simple wrapper function to import an external file into
a buffer for Gnus to save to Org. I think Gnus called it with a buffer
which already contained the ical attachment from the mail message it
was currently viewing.

Now in Mutt if I receive a calendar invite, I can use mailcap to
import it into Org.

#+begin_src text
  text/calendar; emacsclient -e '(rla-import-ical-to-org-capture "%s")' ; copiousoutput
  application/ics; emacsclient -e '(rla-import-ical-to-org-capture "%s")' ; copiousoutput
#+end_src

Please let me know if this works for anyone else. It may be worth
documenting on Worg.

------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-13 13:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-13 13:45 Ical import in Emacs 27.1 core packages Russell Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.