Skip to content

Instantly share code, notes, and snippets.

@keegancsmith
Created August 22, 2018 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keegancsmith/27707e612580aae475bde0994d31e8d1 to your computer and use it in GitHub Desktop.
Save keegancsmith/27707e612580aae475bde0994d31e8d1 to your computer and use it in GitHub Desktop.
(use-package org-gcal
:config
(setq org-gcal-client-id "REDACTED"
org-gcal-client-secret "REDACTED"
org-gcal-file-alist '(("REDACTED" . "~/org-files/gcal.org")
("REDACTED" . "~/org-files/office.org")
("REDACTED" . "~/org-files/oncall.org")))
;; 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)))))
(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