[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: viewing appointments while scheduling event
From: |
Victor A. Stoichita |
Subject: |
Re: viewing appointments while scheduling event |
Date: |
Fri, 04 Jun 2021 18:25:56 +0200 |
I found something that seems to work. I’m posting it here in case
anyone is interested or has better suggestions.
First, I understood that my diary file should read:
&%%(org-diary) ~/calendriers/victor.org
This was clearly explained in the docstring of org-diary (if it was
also in the org-mode manual, then I missed it there).
With this set, one can hit "!" from the minibuffer while scheduling an
event to view the diary for the corresponding date.
I found it a bit cumbersome though to hit "!" after each move in the
calendar. So I ended up with the following code. Pressing "!" now
toggles following the diary when the cursor moves in the calendar.
#+begin_src emacs-lisp
;;;;; Follow diary from calendar when scheduling events
(defvar-local vic/org-read-date-diary t
"Whether to display diary for current calendar date when scheduling an event
from org-mode")
(defun vic/org-read-date-calendar-display-diary (&rest arg)
"Used as advice after `org-eval-in-calendar'. Display diary for that day if
`vic/org-read-date-diary' is non nil."
(when (and vic/org-read-date-diary
;; Check that the cursor was actually moved
;; Otherwise too many calls
(member arg '(((calendar-goto-today))
((calendar-backward-day 1))
((calendar-forward-day 1))
((calendar-backward-week 1))
((calendar-forward-week 1))
((calendar-backward-month 1))
((calendar-forward-month 1))
((calendar-backward-year 1))
((calendar-forward-year 1)))))
(org-eval-in-calendar '(diary-view-entries))
(message "")))
(advice-add 'org-eval-in-calendar :after
'vic/org-read-date-calendar-display-diary)
(defun vic/org-read-date-toggle-diary ()
"Toggle following diary from calendar when scheduling events."
(interactive)
(if vic/org-read-date-diary
(setq vic/org-read-date-diary nil)
(setq vic/org-read-date-diary t)))
(define-key org-read-date-minibuffer-local-map
(kbd "!") 'vic/org-read-date-toggle-diary)
#+end_src
It’s a bit hackish I suppose, partly because I could not find an easy
way to advise the functions in org-read-date-minibuffer-local-map
which are all lambdas. But it seems to work.
I’m still interested in learning from more advanced setups that people
might have for the same purpose (which is: display existing events for
the date that is currently selected in the org-schedule
minibuffer/calendar).
Cheers
Victor