From d12b01955773be64d04bd391d822cf7d1b67f637 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Tue, 12 Jan 2021 00:33:32 -0800 Subject: [PATCH 2/2] org-clock: Query when exiting with running clock It's annoying to accidentally quit Emacs with a running clock, then resolve the clock the next time when Emacs is started. * lisp/org-clock.el (org-clock-kill-emacs-query): New function. --- lisp/org-clock.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 37459580b..bc1762f63 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2886,6 +2886,15 @@ The details of what will be saved are regulated by the variable (if (outline-invisible-p) (org-show-context)))))))))) +(defun org-clock-kill-emacs-query () + "Query user when killing Emacs. +This function is added to `kill-emacs-query-functions'." + (if (org-clocking-buffer) + (y-or-n-p "Org clock is running; exit anyway? ") + t)) + +(add-hook 'kill-emacs-query-functions #'org-clock-kill-emacs-query) + ;; Suggested bindings (org-defkey org-mode-map "\C-c\C-x\C-e" 'org-clock-modify-effort-estimate) -- 2.30.0