As an avid Org mode user, I often find myself using the clocking feature to track the time I spend on different tasks and projects. One thing that can be inconvenient, however, is having to manually recalculate clock tables every time I want to see an updated view of my clocked time.

Fortunately, I recently discovered a simple yet powerful solution to this problem: an elisp function that automatically recalculates clock tables whenever an Org mode file is saved.

To use this function, simply add the following code to your init.el file:

(defun autocalc-clocktable ()
  (when (derived-mode-p 'org-mode)
    (save-excursion
      (goto-char 0)
      (if (string-equal (car
			 (cdr
			  (car
			   (org-collect-keywords '("AUTOCALC_CLOCKTABLES")))))
			"t")
	  (progn
	    (goto-char (search-forward "clocktable"))
	    (org-clock-report))))))

Once this function is defined, you can enable it for a specific Org mode file by adding the following line to the file:

#+AUTOCALC_CLOCKTABLES: t

From then on, every time you save that file, the clock tables within it will be automatically recalculated, allowing you to see an up-to-date view of your clocked time without having to manually run the `org-clock-report` command.

I have found this function to be incredibly useful, as it saves me a lot of time and hassle when working with clock tables in Org mode. Give it a try and see if it helps improve your Org mode workflow as well!


If you liked this post, please consider supporting our Free and Open Source software work – you can sponsor us on Github and Patreon or star our FLOSS repositories.