From: Allen Li <darkfeline@felesatra.moe>
To: Kyle Meyer <kyle@kyleam.com>
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Query when exiting with running clock
Date: Wed, 3 Mar 2021 02:08:48 +0000 [thread overview]
Message-ID: <CADbSrJzNAwgTaPD1zUFVP=Ntuak2ccGBJvSKzW0gg3XxiykkOA@mail.gmail.com> (raw)
In-Reply-To: <878s85ya9u.fsf@kyleam.com>
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
On Wed, Feb 3, 2021 at 5:45 AM Kyle Meyer <kyle@kyleam.com> wrote:
>
> Allen Li writes:
>
> > This is a patch adding a query function when exiting Emacs, warning the
> > user if there is a running clock. This is useful for preventing the
> > user from accidentally leaving dangling clocks. I have had success
> > using a modified personal version of this code.
>
> Thanks. I'd find this useful as well.
Thanks for your feedback. I have addressed your comments. Please see
the new patches.
[-- Attachment #2: 0002-org-clock-Query-when-exiting-with-running-clock.patch --]
[-- Type: text/x-patch, Size: 2083 bytes --]
From e2fa281ca3d5c58fd759011c5f93790f49cb669d Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
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.
(org-clock-ask-before-exiting): New user option.
---
lisp/org-clock.el | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 2a6a9af47..52b486cd8 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -485,6 +485,16 @@ 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)
+
(defvar org-clock-in-prepare-hook nil
"Hook run when preparing the clock.
This hook is run before anything happens to the task that
@@ -3096,6 +3106,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-clock-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)
--
2.30.1
[-- Attachment #3: 0001-org-clock-Replace-org-clocking-buffer-with-org-clock.patch --]
[-- Type: text/x-patch, Size: 2943 bytes --]
From 429dd06ac281a5706c8ce2f3e35dab4aab6b5bfc Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Tue, 12 Jan 2021 00:26:47 -0800
Subject: [PATCH 1/2] org-clock: Replace org-clocking-buffer with
org-clock-is-active
org-clocking-buffer and org-clock-is-active have the same definition.
org-clocking-buffer is defined in org-clock.el while
org-clock-is-active is defined in org.el. org-clock.el requires
org.el.
org-clocking-buffer is kept as an alias to preserve backward
compatibility with any user code.
* lisp/org-clock.el (org-clocking-buffer): Moved to org.el.
* lisp/org.el (org-clocking-buffer): Moved function.
(org-clock-is-active): Made into an alias.
---
lisp/org-clock.el | 4 ----
lisp/org.el | 6 +++---
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index c94f60781..2a6a9af47 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -607,10 +607,6 @@ cannot be translated."
((stringp drawer) drawer)
(t nil))))
-(defun org-clocking-buffer ()
- "Return the clocking buffer if we are currently clocking a task or nil."
- (marker-buffer org-clock-marker))
-
(defun org-clocking-p ()
"Return t when clocking a task."
(not (equal (org-clocking-buffer) nil)))
diff --git a/lisp/org.el b/lisp/org.el
index fd6226702..e35c19a9e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -144,7 +144,6 @@ Stars are put in group 1 and the trimmed body in group 2.")
(declare-function org-clock-timestamps-down "org-clock" (&optional n))
(declare-function org-clock-timestamps-up "org-clock" (&optional n))
(declare-function org-clock-update-time-maybe "org-clock" ())
-(declare-function org-clocking-buffer "org-clock" ())
(declare-function org-clocktable-shift "org-clock" (dir n))
(declare-function org-columns-quit "org-colview" ())
(declare-function org-columns-insert-dblock "org-colview" ())
@@ -3828,10 +3827,11 @@ This is needed for font-lock setup.")
"Marker recording the last clock-in, but the headline position.")
(defvar org-clock-heading ""
"The heading of the current clock entry.")
-(defun org-clock-is-active ()
+(defun org-clocking-buffer ()
"Return the buffer where the clock is currently running.
Return nil if no clock is running."
(marker-buffer org-clock-marker))
+(defalias 'org-clock-is-active #'org-clocking-buffer)
(defun org-check-running-clock ()
"Check if the current buffer contains the running clock.
@@ -8254,7 +8254,7 @@ function is being called interactively."
;; The clock marker is lost when using `sort-subr'; mark
;; the clock with temporary `:org-clock-marker-backup'
;; text property.
- (when (and (eq (org-clock-is-active) (current-buffer))
+ (when (and (eq (org-clocking-buffer) (current-buffer))
(<= start (marker-position org-clock-marker))
(>= end (marker-position org-clock-marker)))
(with-silent-modifications
--
2.30.1
next prev parent reply other threads:[~2021-03-03 2:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 8:55 [PATCH] Query when exiting with running clock Allen Li
2021-02-03 5:45 ` Kyle Meyer
2021-03-03 2:08 ` Allen Li [this message]
2021-03-04 3:54 ` Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADbSrJzNAwgTaPD1zUFVP=Ntuak2ccGBJvSKzW0gg3XxiykkOA@mail.gmail.com' \
--to=darkfeline@felesatra.moe \
--cc=emacs-orgmode@gnu.org \
--cc=kyle@kyleam.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).