7

Context When working on a larger document in org-mode I would like to clock the whole work time without gaps. As I usually have a logbook in each section I wonder if it's possible to automatically clock in when moving the cursor into a section and clock out when leaving it.

As far as I know there are only projects that clock out automatically when finishing tasks and that clock in a default clock afterwards. Although I really like the approach I have the feeling that it's not appropriate when writing a longer document whose sections usually get into the finished state very late and where sometimes jumping between section occurs, for example in periods in which only small issues are fixed.

The first time at least I saw such automatic clocking was in Bernt Hansen's org-mode configuration.

Question: How can automatic clocking be implemented, such that there is a clock-in when moving into a section and a clock-out when moving out of a section?

  • Do you think one could use keyboard input event listener to check wether the key stroke inserted a new character into the buffer and if yes just clock in if a clock is not already running in this section? – Christoph Jun 3 '15 at 10:55
2

This seems pretty close. I set this up to work on sections with an AUTOCLOCK property. I don't know a more elegant way to do it than the post-command-hook.

#+BEGIN_SRC emacs-lisp
(defun action-1 ()
  "hook function to run in headings with a clock"
  (and (eq major-mode 'org-mode)
       (not (org-before-first-heading-p)))
  (if (org-entry-get (point) "AUTOCLOCK")
      (org-clock-in)
    (when (marker-buffer org-clock-marker) (org-clock-out))))

(add-hook 'post-command-hook 'action-1)
#+END_SRC
  • That's great I'll check it out tomorrow! – Christoph Apr 27 '16 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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