Logo courtesy, the Org Mode Website

Lisp is on the list of things to learn someday.1
And in the meanwhile, I need to be able to hack Emacs to do the stuff I want.
But also, there are a ton of other things, that are currently much, much higher on my list of priorities.2
And while the community is extremely kind and generous, the expectation is that you need to put in the time and the work.
Which I currently don’t have and can’t do.

And so, it finally happened.
I signed up for a Claude account and told it to write me some lisp.

I am heavily Org Mode task driven, these days and I have a manual workflow that I need a teensy bit of help with.

  1. I start work on a task
  2. I mark it as WORKING (and clock in manually)
  3. I want to switch to another task
  4. I mark my original task as WAITING (and clock out manually)
  5. I then mark my new task as WORKING (and clock in manually)
  6. After a while I switch to the original task, and clock in manually (after marking the current task as WAITING and clocking out there manually)

What bugs me, is the clocking in and out, because …

  1. I tend to forget it, messing up all my clock times and …
  2. because it is now becoming painful on my middle aged fingers3,

So, like I said, I prompted Claude to give me code that would clock me in automatically, whenever I changed state to WORKING and clock me out when I switched to WAITING4
It spat out some code.
I tried to reasonably guess and verify what it did.
It looked ok.
I tried it.
It worked!
And that’s that.

(defun mjb/org-clock-in-when-task-state-changes-to-working ()
  "Clock in an Org mode task when the status is changed to 'WORKING'."
  (when (and (eq major-mode 'org-mode)
             (member (downcase (or (org-get-todo-state) "")) '("working")))

(defun mjb/org-clock-out-when-task-state-changes-to-waiting ()
  "Clock out an Org mode task when the status is changed to 'WAITING'."
  (when (and (eq major-mode 'org-mode)
             (member (downcase (or (org-get-todo-state) "")) '("waiting")))

;; These lines make the functions above, hook to Org’s state change mechanism.
;; So that everytime a task’s state changes, these functions are called
(add-hook 'org-after-todo-state-change-hook #'mjb/org-clock-in-when-task-state-changes-to-working)
(add-hook 'org-after-todo-state-change-hook #'mjb/org-clock-out-when-task-state-changes-to-waiting)

Reminds me of the old adages about humans and bicycles being the fastest and humans and chess programs5, being the best players.6
All of it is good, if it aids me, and hopefully does not get in my way.

Feedback on this post? Mail me at feedback at this domain

P.S. Subscribe to my mailing list!
Forward these posts and letters to your friends and get them to subscribe!
P.P.S. Feed my insatiable reading habit.

  1. soon ↩︎

  2. getting up to speed with the current devops/cloud landscape, for instance ↩︎

  3. Yes, I could reassign them to easier keys, but just having it done automatically is better ↩︎

  4. the task state switches are second nature and don’t bother me much ↩︎

  5. Centaurs, I think, the combination is called ↩︎

  6. and of course, the pilots and giant mechas in Pacific Rim ↩︎