-
Notifications
You must be signed in to change notification settings - Fork 8
/
cpm-setup-calendars.el
76 lines (67 loc) · 2.81 KB
/
cpm-setup-calendars.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; Calendars
(setq diary-file (concat lem-cache-dir "diary-files/diary"))
(setq diary-location (concat lem-cache-dir "diary-files/"))
(setq diary-display-function 'diary-fancy-display)
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
(add-hook 'diary-list-entries-hook 'diary-sort-entries t)
;; The following doesn't use org-mac-ical but if I were to ever use that this seems relevant
;; https://emacs.stackexchange.com/questions/49117/org-mac-ical-not-working
;; calendars you want to download
;; each item links to a remote iCal calendar
(when (file-directory-p (concat lem-cache-dir "diary-files/"))
(setq calendars
`(("work" . ,cal-work)
("gcal" . ,cal-gcal)
("family" . ,cal-family)
)))
(defun lem--getcal (url file)
"Download ics file and add it to file"
(let ((tmpfile (url-file-local-copy url)))
(icalendar-import-file tmpfile file)
(kill-buffer (car (last (split-string tmpfile "/"))))))
(defun lem-getcals ()
"Load a set of ics calendars into emacs diary files"
(interactive)
(mapc #'(lambda (x)
(let ((file (concat diary-location (car x)))
(url (cdr x)))
(message (concat "Loading " url " into " file))
(find-file file)
;; (flush-lines "^[& ]") ;; if you import ical as non marking
(erase-buffer) ;; to avoid duplicating events
(lem--getcal url file)
))
calendars)
;; send everything to a diary file
(shell-command-to-string "cat work family gcal > diary"))
(defun lem-refresh-ical ()
"get ical appointments via batch emacs call"
(interactive)
(shell-command-to-string "emacs-get-cals.sh")
(lem-org-agenda-refresh))
;; add exchange support
(use-package excorporate
:after org
:disabled t
;; :config
;; configure excorporate
;; allow opening the exchange calendar with 'e' from calendar
;; (evil-define-key 'motion calendar-mode-map "e" #'exco-calendar-show-day)
(setq-default
;; configure email address and office 365 exchange server adddress for exchange web services
excorporate-configuration
(`(,unl-email . ,unl-exchange))
;; integrate emacs diary entries into org agenda
org-agenda-include-diary t
)
;; activate excorporate and request user/password to start connection
(excorporate)
;; enable the diary integration (i.e. write exchange calendar to emacs diary file -> ~/.emacs.d/diary must exist)
(excorporate-diary-enable)
(defun lem-exco-agenda-update-diary ()
"call excorporate to update the diary for today"
(exco-diary-diary-advice (calendar-current-date) (calendar-current-date) #'message "diary updated")
)
;; update the diary every time the org agenda is refreshed
(add-hook 'org-agenda-cleanup-fancy-diary-hook 'lem-exco-agenda-update-diary))
(provide 'cpm-setup-calendars)