]> git.ekhem.eu.org Git - guix.git/commitdiff
[emacs] Connect calfw to Google Calendar API.
authorJakub Czajka <jakub@ekhem.eu.org>
Fri, 2 Jun 2023 17:25:57 +0000 (19:25 +0200)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:53:24 +0000 (19:53 +0100)
emacs/.config/emacs/conf/conf-calendar.el

index 326e67029dd5822db456ac9403ed2969112c871b..789d94b780a1834b5fab4cafa8624e51574a9ecb 100644 (file)
 ;; 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 (<email> . <org file for syncing>)."
+  :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)]
       ("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)