Skip to content

Added layer for synchronizing google-calendars to emacs#8372

Closed
mhkc wants to merge 3 commits into
syl20bnr:developfrom
mhkc:develop
Closed

Added layer for synchronizing google-calendars to emacs#8372
mhkc wants to merge 3 commits into
syl20bnr:developfrom
mhkc:develop

Conversation

@mhkc

@mhkc mhkc commented Feb 15, 2017

Copy link
Copy Markdown

The layer handles synchronization through org-gcal. It also adds an additional
calendar view through calfw.

It can be run stand alone but integrates nicely with org-mode.

Solves feature request #7741

Screenshots

Monthly overview of calendar events and scheduled TODOs
cal-month

Agenda view of what is scheduled for the day
cal-detail

@nixmaniack nixmaniack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I have been using org-gcal and calfw and it's nice to see it coming in spacemacs.
Can you add screenshot of how it looks? It'll give this PR more visibility.

I will try it later and provide more feedback.


(defun google-calendar/init-f ()
"Initialize f"
(use-package f))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacemacs already has dependency on f. This shouldn't be needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure whenever f came with emacs or was provided in some package or layer. I am removing it.

"Initialize alert"
(use-package alert
:init
(setq alert-default-style 'notifications)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required to set it? Since this is platform dependant it'd be better to let user select notification style(or we detect and set up a sane one).
Also there are other packages/layers(slace layer, mu4e-alert) which are setting alert-default-style and I think it's time to consolidate effort to setup alert properly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I just tested it and you are not required to set alert-default-style. I am removing it.

@aaronjensen aaronjensen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great, nice work. It'll be nice to be able to remove my custom code for this.

"ags" 'org-gcal-sync
"agf" 'org-gcal-fetch))
:config
(setq org-gcal-down-days 365) ;; Set org-gcal to download events a year in advance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably wouldn't want this as the default. Maybe this can just be documented as something that can change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default without that ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

60

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be kept default - 365 is too big!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Ill restore the default value and add it to the documentation

:config
(setq org-gcal-down-days 365) ;; Set org-gcal to download events a year in advance
(add-hook 'after-init-hook 'org-gcal-fetch)
(add-hook 'kill-emacs-hook 'org-gcal-sync)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is an asynchronous operation. Does this actually do anything if emacs is being killed immediately? I know it's a last ditch attempt to get calendar entries up, but it'd be surprising if it worked.

(add-hook 'after-init-hook 'org-gcal-fetch)
(add-hook 'kill-emacs-hook 'org-gcal-sync)
(add-hook 'org-capture-after-finalize-hook 'google-calendar/sync-cal-after-capture)
(run-with-idle-timer 600 t 'google-calendar/org-gcal-update)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, there's no way for the calendar to update while emacs is in use throughout the day. org-gcal-fetch is not super disruptive, so I configured my emacs to create a a much shorter idle timer every 10 minutes or so. That way it tries to sync every 10 minutes if emacs is idle for, say, 30 seconds. That way you probably won't have your typing interrupted, but it'd still update while you're using emacs normally. The code to do that is here: https://github.com/aaronjensen/spacemacs.d/blob/fc69c4a1e643ad276268a2409fc736b28ee2ae14/lisp/init-org.el#L71-L106 (probably can be cleaned up a bit, but you get the idea)

"* %^{Description}\n%^{LOCATION}p\n%(cfw:org-capture-day)\n%?"))
#+END_SRC

** Configure alert

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unclear to me what these alerts were for. It seems that they're status messages from the org-gcal sync/fetch, which is not what I would have expected (I would have expected that they were calendar remindrs). AFAICT the only way to get those is with org-agenda-to-appt. Maybe it'd be worth integrating that as well? See here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I previously removed the alert dependency since I came to the same discovery as you. This reference in the README is just remnants from that.

Good point with org-agenda-to-appt. I don't have time to work on integrate it at the moment so I dont think it should be part of this PR.

@@ -0,0 +1,166 @@
#+TITLE: Google calendar layer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have this be the general calendar layer and have org-gcal support just be optional (if a var is set, for example)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends if there are reliable packages that provides synchronization with other popular calendar services. Non Google calendar users could just exclude org-gcal in their dotfile and only use calfw.

"Initializes org-gcal and adds keybindings for it's exposed functions"
(use-package org-gcal
:init
(progn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bug in org-gcal that can cause it to choke on events that are private (Say you share your work calendar with your personal account and your work calendar has something marked private).

This will work around it until it is fixed in org-gcal and may be worth including in this layer:

(push (lambda (event) (plist-get event :summary)) org-gcal-fetch-event-filters)

"Sync calendar after a event was added with org-capture.
The function can be run automatically with the 'org-capture-after-finalize-hook'."
(when-let ((cal-files (mapcar 'f-expand (mapcar 'cdr org-gcal-file-alist)))
(capture-target (f-expand (car (cdr (org-capture-get :target)))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates an error if the file in the org-capture-template is a variable (for example, (file org-default-notes-file))

@robbyoconnor robbyoconnor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotpyfe

dotpyfe commented Jun 13, 2017

Copy link
Copy Markdown

@mkhc do you think you'd be able to complete this soon? id love to use it!

@robbyoconnor

Copy link
Copy Markdown
Contributor

@Voleking -- step 1) use a topic branch; step 2) fix the issues that travis is reporting. With regard to the other issues....don't know

@nixmaniack

Copy link
Copy Markdown
Contributor

@Voleking - Reporting at upstream might be a better idea.

@benreyn

benreyn commented Sep 13, 2017

Copy link
Copy Markdown
Contributor

Just poking my head in here. Does anyone know what the status of this layer is?

@benreyn

benreyn commented Oct 10, 2017

Copy link
Copy Markdown
Contributor

@mhkc, do you have this hosted somewhere that I can clone and use it as a private layer?

Edit: Nevermind, I found it.

mhkc added 3 commits October 23, 2017 08:35
The layer handles synchronization through org-gcal. It also adds an additional
calendar view through calfw.

It can be run stand alone but integrates nicely with org-mode.
@maikol-solis

Copy link
Copy Markdown

It would be awesome if this is pushed to the develop branch.

@smile13241324

Copy link
Copy Markdown
Collaborator

This looks cool, however I have noticed that some of the packages are pretty old, can someone have a short test and confirm that the current google apis are still working with this layer?

If it does I would volunteer to see what needs to be done to get this integrated into develop somewhere.

@smile13241324 smile13241324 added the Need test report We require a test before this can be merged, best by someone working in the related language label May 3, 2021
@bhw-foss

Copy link
Copy Markdown
Contributor

I have tested this layer on

Ubuntu 20.04
GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2020-09-19
Org mode version 9.4.6 (9.4.6-elpaplus @ /home/hanshen/.emacs.d/elpa/27.1/develop/org-plus-contrib-20210519/)
Spacemacs v.0.300.0 Commit: 2515f14
Latest on MELPA

Everything works as expected so far. I had previously setup org-gcal
independently and as far as I'm concerned that's the hardest step.

Only minor change needed is inclusion of the calfw-org package as discussed here mhkc/google-calendar-layer#8

Original PR has archived his repo. I have a forked version here, ready to test:

https://github.com/HanshenWang/google-calendar-layer

Where I've gone through the issues and PRs of the original and added minor fixups
where needed. It should work OOTB with instructions under the README install.

As it currently stands, I do believe it needs more testing before it can be
safely merged.

Specifically how google-calendar/org-gcal-update is going to be called. Via
run-with-idle-timer modified as aaronjensen mentioned above or perhaps
org-agenda-mode-hook?

To be clear, on the whole I am very grateful for the work done already. I
plan continuing to use the layer. Org-gcal is a needed QOL if one decides to use
org agenda semi-seriously. I know of and use Orgzly (for Android), but having a calendar that
is open to collaboration helps with that famous weak point of org mode.

Calfw is a nicety, but useful enough that I am sticking with it. I do wonder how
much interest there is though, and is there enough overlap between freedom loving
Emacs ideologues and people like myself who have drank some of the google koolaid?

@maikol-solis Are you still using this layer? How does it work for you?

@lebensterben

Copy link
Copy Markdown
Contributor

@HanshenWang
you can open a new PR and add OP as co-author

@bhw-foss

Copy link
Copy Markdown
Contributor

@lebensterben It would be better for someone else to carry this PR across the
finish line. I am content right now with this as a private layer. I definitely
agree should you close this PR, it's been 5 years.

Cheers,

@smile13241324

Copy link
Copy Markdown
Collaborator

Lets close this, we can have a new PR which is using a more up-to-date code base if this feature is still wished by enough people.

@robbyoconnor

Copy link
Copy Markdown
Contributor

I could take this on at some point and bring it up to date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Help wanted Need test report We require a test before this can be merged, best by someone working in the related language New Layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.