emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ical import in Emacs 27.1 core packages


From: Russell Adams
Subject: Ical import in Emacs 27.1 core packages
Date: Thu, 13 Aug 2020 15:45:38 +0200

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]