kidd / org-gcal.el

Org sync with Google Calendar. (active maintained project as of 2019-11-06)
439 stars 47 forks source link

[Question] Is it possible to fetch events from remote calendar and put them inside a specific heading in the destination file? #229

Open gusgustavsohn opened 1 year ago

gusgustavsohn commented 1 year ago

Let me begin by saying that Org-gcal is working fine for me, it is indeed a great tool. Thanks to everyone involved in its development and maintenance!

Now to the point of my question. I've noticed that the file that is the destination of the org-gcal-fetch-command could quickly get messy as all entries in my google calendar are fetched and appended to that file as level 1 headings.

My question is: could it be possible to tell org-gcal to put all entries from a given calendar inside a specific heading on the destination file set by org-gcal-fetch-file-alist? If it is indeed possible, I would very much appreciate your help in telling me how to achieve this. I've read the README but I couldn't find any info on this.

Thanks in advance for all your help.

telotortium commented 1 year ago

Hi @gusgustavsohn currently that is not supported directly, although I could consider it as a feature request. Instead, you could write a hook in org-gcal-after-update-entry-functions that moves the entry if it has just been fetched. I don't have time right now to provide a complete example, but here's an example of how org-gcal-after-update-entry-functions is used - the update-mode argument is set to 'newly-fetched for newly-fetched entries. Then you could use org-refile to move the tree, although you'll have to look up how to construct the rfloc argument to org-refile - shouldn't be too hard.

  (defun my-org-gcal-default-todo-meeting (_calendar-id event _update-mode)
    "Set all events with no TODO heading to be MEETING by default.
Applies only for files in ‘org-gcal-fetch-file-alist’."
    (when-let* ((title (plist-get event :summary))
                ((member (abbreviate-file-name buffer-file-name)
                         (mapcar #'cdr org-gcal-fetch-file-alist)))
                ((string= "" (org-get-todo-state)))
                ((not (string= "transparent"
                               (org-entry-get (point) "TRANSPARENCY")))))
      (let ((org-inhibit-logging t))
        (org-todo "MEETING"))))
  (add-hook 'org-gcal-after-update-entry-functions
            #'my-org-gcal-default-todo-meeting)