diff options
Diffstat (limited to 'modules/org-gcal-config.el')
| -rw-r--r-- | modules/org-gcal-config.el | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/modules/org-gcal-config.el b/modules/org-gcal-config.el index f3e1b7e0..0c309a0e 100644 --- a/modules/org-gcal-config.el +++ b/modules/org-gcal-config.el @@ -38,6 +38,11 @@ (require 'host-environment) (require 'user-constants) +;; Forward declare org-gcal internal variables and functions +(eval-when-compile + (defvar org-gcal--sync-lock)) +(declare-function org-gcal-reload-client-id-secret "org-gcal") + (defun cj/org-gcal-clear-sync-lock () "Clear the org-gcal sync lock. Useful when a sync fails and leaves the lock in place, preventing future syncs." @@ -48,7 +53,7 @@ Useful when a sync fails and leaves the lock in place, preventing future syncs." (defun cj/org-gcal-convert-all-to-org-managed () "Convert all org-gcal events in current buffer to Org-managed. -Changes all events with org-gcal-managed property from 'gcal' to 'org', +Changes all events with org-gcal-managed property from `gcal' to `org', enabling bidirectional sync so changes push back to Google Calendar." (interactive) (let ((count 0)) @@ -62,6 +67,7 @@ enabling bidirectional sync so changes push back to Google Calendar." (message "Converted %d event(s) to Org-managed" count))) (use-package org-gcal + :vc (:url "https://github.com/cjennings/org-gcal" :rev :newest) :defer t ;; unless idle timer is set below :bind (("C-; g" . org-gcal-sync) ("C-; G" . cj/org-gcal-clear-sync-lock)) @@ -99,16 +105,25 @@ enabling bidirectional sync so changes push back to Google Calendar." (require 'plstore) (setq plstore-cache-passphrase-for-symmetric-encryption t) - ;; Enable debugging for HTTP requests - (require 'request) - (setq request-log-level 'debug) - (setq request-message-level 'debug) - ;; set org-gcal timezone based on system timezone (setq org-gcal-local-timezone (cj/detect-system-timezone)) ;; Reload client credentials (should already be loaded by org-gcal, but ensure it's set) - (org-gcal-reload-client-id-secret)) + (org-gcal-reload-client-id-secret) + + ;; Auto-save gcal files after sync completes + (defun cj/org-gcal-save-files-after-sync (&rest _) + "Save all org-gcal files after sync completes." + (dolist (entry org-gcal-fetch-file-alist) + (let* ((file (cdr entry)) + (buffer (get-file-buffer file))) + (when (and buffer (buffer-modified-p buffer)) + (with-current-buffer buffer + (save-buffer) + (message "Saved %s after org-gcal sync" (file-name-nondirectory file))))))) + + ;; Advise org-gcal--sync-unlock which is called when sync completes + (advice-add 'org-gcal--sync-unlock :after #'cj/org-gcal-save-files-after-sync)) ;; Set up automatic initial sync on boot with error handling ;;(run-with-idle-timer |
