Skip to content

Instantly share code, notes, and snippets.

@billylindeman
Last active June 25, 2018 07:17
Show Gist options
  • Save billylindeman/bced48e4944ee0da519caa4d09b2c923 to your computer and use it in GitHub Desktop.
Save billylindeman/bced48e4944ee0da519caa4d09b2c923 to your computer and use it in GitHub Desktop.
;; org-gcal wrappers to only sync with a timeout
(defvar org-gcal-fetch-last-run (current-time)
"Timestamp of the last time org-gcal-fetch-store-time was run")
(defun org-gcal-fetch-with-timeout (timeout)
(interactive)
"Runs org-gcal-fetch only if the last time this function was called is > the timeout"
(let ((time-since-last-run
(float-time (time-subtract (current-time) org-gcal-fetch-last-run))))
(when (> time-since-last-run timeout) ;; was the last run longer than our timeout
(org-gcal-fetch)
(set 'org-gcal-fetch-last-run (current-time)))))
;; in the agenda mode hook we call the sync with timeout @ 15 seconds
(with-eval-after-load 'org (add-hook 'org-agenda-mode-hook (lambda () (org-gcal-fetch-with-timeout 15.0))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment