org-caldav
org-caldav copied to clipboard
org-caldav-sync with async
Here, this change does not make org-caldav to be in the background.
Maybe this is because sometimes it creates new IDs in the files, and then it askes me to save the file or not before it continues. 'always
should maybe also save the files?
Here is my config:
(require 'org-caldav)
(setq org-caldav-url "https://www.google.com/calendar/dav"
org-caldav-resume-aborted 'always
org-icalendar-timezone "Europe/Berlin"
org-icalendar-include-body nil
)
(setq org-caldav-calendars
;; some calendar definitions for 4 differente google calendars skipped here
)
;; sync async
(defun org-caldav-async ()
"syncing org-caldav with async."
(interactive)
(async-start
;; Sync caldav
(org-caldav-sync)
(lambda (result)
(message "Caldav sync finished with %s" result)))
)
(global-set-key "\C-cs" 'org-caldav-async)
Maybe you can tell me what's wrong?
Do M-x toggle-debug-on-quit before the sync and hit C-g when the question pops up. You should get a backtrace from which I can see what exactly triggered the question. I'm also assuming that it is because the exporter changed one of the Org files, but I'm hesitant to blindly save them.
There can be different things:
Debugger entered--Lisp error: (quit)
signal(quit nil)
y-or-n-p("Delete this entry? ")
org-caldav-update-events-in-org()
#[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5]()
funcall(#[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5])
(let ((org-caldav-inbox (quote (id "8c4dc0dc-bb33-435d-824f-d859928c4dfc"))) (org-caldav-files (quote ("~/Dokumente/org/gtd.org"))) (org-caldav-calendar-id (quote "[email protected]"))) (funcall (quote #[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5])))
eval((let ((org-caldav-inbox (quote (id "8c4dc0dc-bb33-435d-824f-d859928c4dfc"))) (org-caldav-files (quote ("~/Dokumente/org/gtd.org"))) (org-caldav-calendar-id (quote "[email protected]"))) (funcall (quote #[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5]))))
org-caldav-sync-calendar((:calendar-id "[email protected]" :files ("~/Dokumente/org/gtd.org") :inbox (id "8c4dc0dc-bb33-435d-824f-d859928c4dfc")))
org-caldav-sync()
(async-start (org-caldav-sync) (function (lambda (result) (message "Caldav sync finished with %s" result))))
org-caldav-async()
funcall-interactively(org-caldav-async)
call-interactively(org-caldav-async nil nil)
command-execute(org-caldav-async)
this is another bt:
Debugger entered--Lisp error: (quit)
signal(quit nil)
y-or-n-p("Save file /home/martin/Dokumente/org/gtd.org? ")
org-release-buffers((#<killed buffer> #<killed buffer> #<buffer gtd.org> #<buffer kramer.org> #<buffer hauselberger.org> #<buffer ruff.org> #<buffer Schwedenkalender.org> #<buffer centrocal.org> #<buffer PHNA.org> #<buffer someday.org> #<buffer kehl.org> #<buffer Schwedenprojekt.org> #<buffer from-mobile.org> #<buffer capture.org>))
#[0 "\301!\207" [org-agenda-new-buffers org-release-buffers] 2]()
org-icalendar--combine-files("~/Dokumente/org/gtd.org")
apply(org-icalendar--combine-files "~/Dokumente/org/gtd.org")
org-caldav-generate-ics()
#[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5]()
funcall(#[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5])
(let ((org-caldav-inbox (quote (id "8c4dc0dc-bb33-435d-824f-d859928c4dfc"))) (org-caldav-files (quote ("~/Dokumente/org/gtd.org"))) (org-caldav-calendar-id (quote "[email protected]"))) (funcall (quote #[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5])))
eval((let ((org-caldav-inbox (quote (id "8c4dc0dc-bb33-435d-824f-d859928c4dfc"))) (org-caldav-files (quote ("~/Dokumente/org/gtd.org"))) (org-caldav-calendar-id (quote "[email protected]"))) (funcall (quote #[nil "\306\307 !C\"\310\211\203# @\311\n!\204 \312\313\n\"\210A\211\204 *\f9\2031 \314\f!\210\315\f!\210\316 \210
\204o \317 \310\320 \210\310\211\203f @\211\310\321!\240*\210A\211\204L *\322!\210\323 \210\324!\210\325 \210\326 \210\310rq\210\327\310!\210\330 \210)\331\332!!\207" [org-caldav-files org-caldav-inbox filename --dolist-tail-- org-caldav-url resume append org-caldav-inbox-file nil file-exists-p user-error "File %s does not exist" org-caldav-check-oauth2 org-caldav-retrieve-oauth2-token org-caldav-check-connection org-caldav-generate-ics org-caldav-load-sync-state last org-caldav-update-eventdb-from-org org-caldav-update-eventdb-from-cal org-caldav-update-events-in-cal org-caldav-update-events-in-org org-caldav-save-sync-state set-buffer-modified-p kill-buffer delete-file buffer-file-name org-caldav-ics-buffer org-caldav-event-list cur status event] 5]))))
org-caldav-sync-calendar((:calendar-id "[email protected]" :files ("~/Dokumente/org/gtd.org") :inbox (id "8c4dc0dc-bb33-435d-824f-d859928c4dfc")))
org-caldav-sync()
(async-start (org-caldav-sync) (function (lambda (result) (message "Caldav sync finished with %s" result))))
org-caldav-async()
funcall-interactively(org-caldav-async)
call-interactively(org-caldav-async nil nil)
command-execute(org-caldav-async)
hitting C-g on "Delete this entry?" ran me now into trouble, I'm now asked on most appointments to delete this entry, even if it is on my google calendar. so what is wrong now?
The first issue can be avoided by simply setting org-caldav-delete-org-entries to 'always or 'never, depending on how you want to handle deleted calendar events. The second one comes from org-release-buffers and hence is something out of my control. As you assumed, it happens because the icalendar exporter changed the Org file, and now Org asks for permission to save before it kills the buffer. As far as I can see, there's no option to disable that. You could ask on the Org mailing list to add an option for that. You can hack your way around it, though. The super-hacky way would be to bind y-or-n-p to something that always returns 'y'. A better way would be to add something to org-icalendar-after-save-hook that saves your Org files. Regarding your last problem, I don't know what happened. It's best to simply start from scratch. If that's not possible: Set org-caldav-delete-org-entries to 'never for the time being.
I've looked at this problem, and I believe an idea would be to create all the UID (and save them) not in async, and then run org-caldav-sync
something like
(defun org-caldav-async ()
"syncing org-caldav with async."
(interactive)
(dolist (file org-caldav-files)
(with-current-buffer (org-get-agenda-file-buffer file)
(org-icalendar-create-uid file t))))
(org-release-buffers org-agenda-new-buffers)
(async-start
;; Sync caldav
(org-caldav-sync)
(lambda (result)
(message "Caldav sync finished with %s" result)))
Obviously, my code make the assumption you are not using org-caldav-calendars.
Also this code is untested. May be adding a (save-some-buffers)
after (or before) org-release-buffers
would be a good idea.
I thought about that, but now I think that async doesn't work if the code could cause in user interaction. But I will try your version...
@grauschnabel, that might be too late but I just found that issue and I noticed you are not calling org-caldav-sync
asynchronously. Since you are not wrapping it in a (lambda () ...)
, you are actually evaluating (org-caldav-sync)
before you call async-start
.
In reality, it might not be possible to do what you want since the new emacs process that is spawned knows nothing about org-caldav
.