[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 303e7c2 1/3: org-clock: Query when exiting with run
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 303e7c2 1/3: org-clock: Query when exiting with running clock |
Date: |
Wed, 3 Mar 2021 22:57:09 -0500 (EST) |
branch: externals/org
commit 303e7c28e4fcb8cfd374d82f26a02b8a6c73184a
Author: Allen Li <darkfeline@felesatra.moe>
Commit: Kyle Meyer <kyle@kyleam.com>
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.
(org-clock-ask-before-exiting): New user option.
[km: added package-version keyword, fixed function name typo]
---
lisp/org-clock.el | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index c94f607..4e6cac1 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -485,6 +485,17 @@ is added to the user configuration."
(integer :tag "Clock out after Emacs is idle for X seconds")
(const :tag "Never auto clock out" nil)))
+(defcustom org-clock-ask-before-exiting t
+ "If non-nil, ask if the user wants to clock out before exiting Emacs.
+This variable only has effect if set with \\[customize]."
+ :set (lambda (symbol value)
+ (if value
+ (add-hook 'kill-emacs-query-functions
#'org-clock-kill-emacs-query)
+ (remove-hook 'kill-emacs-query-functions
#'org-clock-kill-emacs-query))
+ (set symbol value))
+ :type 'boolean
+ :package-version '(Org . "9.5"))
+
(defvar org-clock-in-prepare-hook nil
"Hook run when preparing the clock.
This hook is run before anything happens to the task that
@@ -3100,6 +3111,17 @@ The details of what will be saved are regulated by the
variable
(when (org-invisible-p) (org-show-context))))))
(_ nil)))))
+(defun org-clock-kill-emacs-query ()
+ "Query user when killing Emacs.
+This function is added to `kill-emacs-query-functions'."
+ (let ((buf (org-clocking-buffer)))
+ (when (and buf (yes-or-no-p "Clock out and save? "))
+ (with-current-buffer buf
+ (org-clock-out)
+ (save-buffer))))
+ ;; Unconditionally return t for `kill-emacs-query-functions'.
+ t)
+
;; Suggested bindings
(org-defkey org-mode-map "\C-c\C-x\C-e" 'org-clock-modify-effort-estimate)