From 85497c2c69b9413e68c4a96fb6af1fd31285d809 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Fri, 2 Jun 2023 19:25:57 +0200 Subject: [PATCH] [emacs] Connect calfw to Google Calendar API. --- emacs/.config/emacs/conf/conf-calendar.el | 98 +++++++++++++++++++---- 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/emacs/.config/emacs/conf/conf-calendar.el b/emacs/.config/emacs/conf/conf-calendar.el index 326e670..789d94b 100644 --- a/emacs/.config/emacs/conf/conf-calendar.el +++ b/emacs/.config/emacs/conf/conf-calendar.el @@ -4,24 +4,102 @@ ;; conf-calendar.el - configuration for the calendar. (require 'conf-package) +(require 'conf-variables) + +(defcustom conf:gcal-client-id + "" + "OAuth2 client ID tied to the Calendar API Google Cloud project." + :type 'string + :group 'conf:configuration) + +(defcustom conf:gcal-client-secret + "" + "OAuth2 client secret tied to the Calendar API Google Cloud project." + :type 'string + :group 'conf:configuration) + +(defcustom conf:gcal-calendar-id-org-file-map + "" + "List of pairs ( . )." + :type '(alist :key-type string :value-type string) + :group 'conf:configuration) + +(defcustom conf:gcal-encryption-key-id + "" + "GPG private key ID used to encrypt OAuth2 credentials cache." + :type 'string + :group 'conf:configuration) + +(use-package plstore + :ensure t + :config + (add-to-list 'plstore-encrypt-to conf:gcal-encryption-key-id)) + +(use-package org-gcal + :after + (plstore) + :ensure t + :custom + (org-gcal-client-id conf:gcal-client-id) + (org-gcal-client-secret conf:gcal-client-secret) + (org-gcal-fetch-file-alist conf:gcal-calendar-id-org-file-map)) (use-package calfw - :requires - (conf-keys) :ensure t :bind (:map cfw:calendar-mode-map ("d" . cfw:navi-goto-date-command) ("g" . cfw:refresh-calendar-buffer)) :custom - (calendar-holidays holiday-christian-holidays) + (calendar-holidays holiday-christian-holidays)) + +(use-package calfw-org + :after + (org-gcal) + :ensure t + :bind + ("C-c k" . conf:open-calendar) :config + (defun conf:open-calendar () + "Custom `calfw' calendar." + (interactive) + (require 'calfw) + (cfw:open-calendar-buffer + :contents-sources (list (cfw:org-create-source "Green")))) + + (defun conf:get-org-file-for-calendar-id () + (let* ((calendar-id + (completing-read "Select account: " + (mapcar 'car conf:gcal-calendar-id-org-file-map))) + (gcal-file (cdr (assoc calendar-id + conf:gcal-calendar-id-org-file-map)))) + (find-file gcal-file) + (end-of-buffer) + (open-line 2))) + (setq cfw:org-capture-template + '("c" "calendar event" entry + (function conf:get-org-file-for-calendar-id) + "* %?")) + (add-to-list 'org-capture-templates cfw:org-capture-template) + + (defun conf:org-gcal-delete-at-point () + (interactive) + (let ((marker (get-text-property (point) 'org-marker))) + (switch-to-buffer (marker-buffer marker)) + (goto-char (marker-position marker)) + (org-gcal-delete-at-point))) + (transient-define-prefix conf:calfw-transient () "Transient keymap with usefeul commands for `calfw'." [["General" ("t" "today" cfw:navi-goto-today-command) ("d" "date" cfw:navi-goto-date-command) ("g" "refresh" cfw:refresh-calendar-buffer)] + ["State" + ("s" "sync" org-gcal-sync) + ("u" "update id" org-gcal-reload-client-id-secret) + ("+" "insert" cfw:org-capture) + ("-" "delete" conf:org-gcal-delete-at-point)] ["Day" ("b" "previous" cfw:navi-previous-day-command) ("f" "next" cfw:navi-next-day-command)] @@ -42,18 +120,4 @@ ("M" "month" cfw:change-view-month)]]) (define-key cfw:calendar-mode-map "?" '("transient" . conf:calfw-transient))) -(use-package calfw-org - :requires - (conf-org) - :ensure t - :bind - ("C-c k" . conf:open-calendar) - :config - (defun conf:open-calendar () - "Custom `calfw' calendar." - (interactive) - (require 'calfw) - (cfw:open-calendar-buffer - :contents-sources (list (cfw:org-create-source "Green"))))) - (provide 'conf-calendar) -- 2.39.5