From 4cd3b3371dcf77171b98dc12f48da248b2f703b2 Mon Sep 17 00:00:00 2001 From: Raul Benencia Date: Tue, 21 Feb 2023 07:58:52 -0800 Subject: emacs: export calendar to ics --- .emacs.local.d/lisp/config/rul-config-org.el | 3 +++ .emacs.local.d/modes/org.el | 29 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.emacs.local.d/lisp/config/rul-config-org.el b/.emacs.local.d/lisp/config/rul-config-org.el index 020efa4..a16e525 100644 --- a/.emacs.local.d/lisp/config/rul-config-org.el +++ b/.emacs.local.d/lisp/config/rul-config-org.el @@ -13,6 +13,9 @@ my-org-journal-time-format "" my-org-refile-path "~/refile.org" my-org-roam-directory "~/org/roam/" + + my-org-agenda-private-local-path "/tmp/example.ics" + my-org-agenda-private-remote-path "/sshx:user@host:example.ics" ) (provide 'rul-config-org) diff --git a/.emacs.local.d/modes/org.el b/.emacs.local.d/modes/org.el index ce4695a..c22047e 100644 --- a/.emacs.local.d/modes/org.el +++ b/.emacs.local.d/modes/org.el @@ -110,7 +110,15 @@ ;; Based on Prot's config: ;; https://protesilaos.com/codelog/2021-12-09-emacs-org-block-agenda/ (setq my-org-agenda-custom-commands - `(("P" "Projects and tasks" + `( + ("X" "Export files" agenda "-CANCELLED" + ((org-agenda-with-colors nil) + (org-agenda-prefix-format "%t %s") + (org-agenda-current-time-string ,(car (last org-agenda-time-grid))) + (org-agenda-fontify-priorities nil) + (org-agenda-remove-tags t)) + ,(list my-org-agenda-private-local-path)) + ("P" "Projects and tasks" ( (agenda "" ( (org-agenda-overriding-header "📌 Today's agenda\n") @@ -686,3 +694,22 @@ as the default task." ;; org-modern (add-hook 'org-mode-hook 'org-modern-mode) (add-hook 'org-agenda-finalize-hook #'org-modern-agenda) + +;; Credits: https://200ok.ch/posts/2022-02-13_integrating_org_mode_agenda_into_other_calendar_apps.html +(defun org-agenda-export-to-ics () + (set-org-agenda-files) + ;; Run all custom agenda commands that have a file argument. + (org-batch-store-agenda-views) + + ;; Org mode correctly exports TODO keywords as VTODO events in ICS. + ;; However, some proprietary calendars do not really work with + ;; standards (looking at you Google), so VTODO is ignored and only + ;; VEVENT is read. + (with-current-buffer (find-file-noselect org-agenda-private-local-path) + (goto-char (point-min)) + (while (re-search-forward "VTODO" nil t) + (replace-match "VEVENT")) + (save-buffer)) + + ;; Copy the ICS file to a remote server (Tramp paths work). + (copy-file org-agenda-private-local-path org-agenda-private-remote-path t)) -- cgit v1.2.3