When I create appointments in Emacs diary
via the calendar
, I have to save changes to the diary file before being able to exit the calendar. I have tried to set up Emacs to automatically save the diary file once changes have been made with this code:
(add-hook 'diary-mode-hook
(lambda ()
(add-hook 'auto-save-hook 'diary-show-all-entries nil t)
(auto-save-mode)))
However, hitting q
in calendar still prompts me with these words:
Diary modified; do you really want to exit the calendar? (y or n)
This from calendar.el:
(defun calendar-exit (&optional kill)
"Get out of the calendar window and hide it and related buffers."
(interactive "P")
(let ((diary-buffer (get-file-buffer diary-file))
(calendar-buffers (calendar-buffer-list)))
(when (or (not diary-buffer)
(not (buffer-modified-p diary-buffer))
(yes-or-no-p
"Diary modified; do you really want to exit the calendar? "))
(if (and calendar-setup (display-multi-frame-p))
;; FIXME: replace this cruft with the `quit-restore' window property
(dolist (w (window-list-1 nil nil t))
(if (and (memq (window-buffer w) calendar-buffers)
(window-dedicated-p w))
(if (eq (window-deletable-p w) 'frame)
(if calendar-remove-frame-by-deleting
(delete-frame (window-frame w))
(iconify-frame (window-frame w)))
(quit-window kill w))))
(dolist (b calendar-buffers)
(quit-windows-on b kill))))))
I would like to be able to save the diary file automatically and exit calendar without confirmation.
before
advice tocalendar-exit
to save the diary: doC-h i g (elisp)Advising RET
for more information.user-error: No such node or anchor: Advising
(advice-add 'calendar-exit :before 'my/save-calendar-before-exit)
C-h i
do you see the Elisp manual? If not, you should install it. You could use the online docs as @BrianCully suggests, but that is no substitute for using Info in emacs itself.