From 7c1ae2a1b7c0674664d97d06a61c232920a72b90 Mon Sep 17 00:00:00 2001 From: Frederik Vanrenterghem Date: Wed, 5 Mar 2025 12:31:34 +0800 Subject: [PATCH 1/1] Support Org mode calendar management in full. * Retire secondary Nextcloud calendar. * Use default calendar for syncing with Org mode. * Update Org capture template to more easily set appointment duration. * Default explicitly to asking before deleting calendar events. --- emacs/.emacs.d/init.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index e5c157d..6f6fc16 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -114,7 +114,7 @@ vc-follow-symlinks t ("C-c a" . org-agenda)) :custom (org-default-notes-file "~/Nextcloud/notes/inbox.org") - (org-agenda-files `(,org-default-notes-file "~/Nextcloud/notes/calendar.org")) + (org-agenda-files `(,org-default-notes-file "~/Nextcloud/notes/calendar-nextcloud.org")) (org-capture-bookmark nil) ;; Capture templates (org-capture-templates @@ -125,8 +125,8 @@ vc-follow-symlinks t (file "~/Documents/belastingen/FY24-25.org") "* %t %a\n") ("a" "Appointment" entry - (file+olp+datetree "~/Nextcloud/notes/calendar.org") - "* %?\n :PROPERTIES:\n :location: %^{Location}\n :END:\n%^T--%^T\n\n" + (file+olp+datetree "~/Nextcloud/notes/calendar-nextcloud.org") + "* %?\n :PROPERTIES:\n :location: %^{Location}\n :END:\n%(fv/org-capture-appointment-timestamp)\n\n" :jump-to-captured t :empty-lines 1 :tree-type month @@ -142,7 +142,7 @@ vc-follow-symlinks t (file+headline org-default-notes-file "Tasks") "* TODO %i%?") ("e" "Email follow-up" entry (file+headline org-default-notes-file "Tasks") - "* TODO %:fromname: %a %?\nDEADLINE: %(org-insert-time-stamp (org-read-date nil t \"+2d\"))"))) + "* TODO %:fromname: %a %?\nDEADLINE: %(org-insert-time-stamp (org-read-date nil t \"+2d\") t)"))) ;; Agenda views (org-agenda-custom-commands '(("P" "Expired calendar events" ((tags "TIMESTAMP<=\"\""))) @@ -174,17 +174,29 @@ vc-follow-symlinks t '((R . t) (latex . t)))) +(defun fv/org-capture-appointment-timestamp (&optional duration) + "Get an Org timestamp for an appointment. +Prompt for a start time, calculate the end time by adding DURATION (default 30 +minutes), and return a formatted Org timestamp with start and end times." + (let* ((duration (or duration 30)) + (start-time (org-read-date t t nil "From:")) + (end-time (time-add start-time (seconds-to-time (* duration 60))))) + (concat (format-time-string (org-time-stamp-format t) start-time) + "--" + (format-time-string (org-time-stamp-format t) end-time)))) + (use-package org-caldav :ensure t :config (setq org-caldav-url "https://owncloud.vanrenterghem.biz/remote.php/dav/calendars/frederik") - (setq org-caldav-calendar-id "orgmode") + (setq org-caldav-calendar-id "default%20calendar") ;; Org filename where new entries from calendar stored - (setq org-caldav-inbox "~/Nextcloud/notes/calendar.org") + (setq org-caldav-inbox '(file+olp+datetree "~/Nextcloud/notes/calendar-nextcloud.org")) ;; Additional Org files to check for calendar events (setq org-caldav-files nil) ;; Usually a good idea to set the timezone manually - (setq org-icalendar-timezone "Australia/Perth")) + (setq org-icalendar-timezone "Australia/Perth") + (setq org-caldav-delete-calendar-entries 'ask)) (use-package org-protocol) -- 2.39.5