From ca98848895da7c540e4f20049df53d08dcadddd9 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Sat, 11 Jan 2025 18:07:43 +0100 Subject: [PATCH] org-timer-done-hook: Run before the timer is stopped * lisp/org-timer.el (org-timer--run-countdown-timer): Stop the timer and unset variables _after_ `org-timer-done-hook' is ran. This way, timer data is available for the hook functions. * etc/ORG-NEWS (~org-timer-done-hook~ is now ran before the timer is stopped): Announce the change. Link: https://orgmode.org/list/a25376e4-f6f6-421d-a8f2-ce280e8d2b15@app.fastmail.com --- etc/ORG-NEWS | 5 +++++ lisp/org-timer.el | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index c9bb192de3..328accc216 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -391,6 +391,11 @@ capture ~:tree-type~ options]], the internal variable undocumented helper function ~org-datetree-insert-line~. ** Miscellaneous +*** ~org-timer-done-hook~ is now ran before the timer is stopped + +Previously, ~org-timer-countdown-timer~ and ~org-timer-start-time~ +were unset when the hook is ran. Now, they still hold the timer info. + *** ox-latex: LaTeX images are now stored alongside the exported =.html= file Previously, LaTeX images (when HTML export does use images for LaTeX) diff --git a/lisp/org-timer.el b/lisp/org-timer.el index 9d4e350429..ee13fbe193 100644 --- a/lisp/org-timer.el +++ b/lisp/org-timer.el @@ -108,7 +108,8 @@ (defvar org-timer-set-hook nil "Hook run after countdown timer is set.") (defvar org-timer-done-hook nil - "Hook run after countdown timer reaches zero.") + "Hook run after countdown timer reaches zero. +The hook is ran before the timer is actually stopped.") ;;;###autoload (defun org-timer-start (&optional offset) @@ -470,11 +471,11 @@ (defun org-timer--run-countdown-timer (secs title) (sound org-clock-sound)) (run-with-timer secs nil (lambda () - (setq org-timer-countdown-timer nil - org-timer-start-time nil) - (org-notify msg sound) - (org-timer-set-mode-line 'off) - (run-hooks 'org-timer-done-hook))))) + (org-notify msg sound) + (org-timer-set-mode-line 'off) + (run-hooks 'org-timer-done-hook) + (setq org-timer-countdown-timer nil + org-timer-start-time nil))))) (defun org-timer--get-timer-title () "Construct timer title. -- 2.47.1