3

Sometimes when we use "clock in" command in org mode and forget to clock out before exit emacs. When we open emacs again and try to "clock in" with the same entry. There always popup with something for us to choose. Does there exists some command to reminds us to clock out when we exits emacs or just choose "clock out" when we exit emacs?

1
  • If one or more of the answers below resolves your question could you flag those answers as correct? Thanks. Jan 31, 2018 at 17:08

2 Answers 2

3

I use the following in my init file to solve exactly this problem. I probably cribbed this from somewhere myself but it's been so long I can't remember the source.

(defun my/org-clock-query-out ()
  "Ask the user before clocking out.
This is a useful function for adding to `kill-emacs-query-functions'."
  (if (and
       (featurep 'org-clock)
       (funcall 'org-clocking-p)
       (y-or-n-p "You are currently clocking time, clock out? "))
      (org-clock-out) 
    t)) ;; only fails on keyboard quit or error

;; timeclock.el puts this on the wrong hook!
(add-hook 'kill-emacs-query-functions 'my/org-clock-query-out)
0
1

If you really want to do it, it can be done.

There are two standard hooks that you can use when emacs exits: kill-emacs-hook and kill-emacs-query-functions. The former is simple to use for always clocking out when you exit emacs:

(add-hook 'kill-emacs-hook #'org-clock-out) 

List of standard hooks: https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Hooks.html

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.