2025-12-22 Summing effort estimates, my way

For some time now I’ve been planning my tasks for the upcoming week every Sunday morning. Not for my day job – this is not something I want to bother my mind with on Sundays, and besides we have Jira for that – but for my personal life. Stuff like doing things around the house, planning doctor’s appointments, etc. For each task I estimate the time it’s going to take, and I don’t want to plan more than some fixed amount of time per week. Naturally, I’d like to have the total time counted for me by my computer.

Now, Org mode already has me covered – I can associate effort estimates with tasks and use column view to sum them up. Trouble is, I usually plan my week in a plain list under a single Org mode headline, and effort estimates only work for actual subheadlines. Right now, I’m doing things this way: my planned tasks are kept in a plain list (with checkboxes), the time estimates are at the end of each task, in parentheses, and the corresponding tasks are kept in a separate subtree where I actually clock them, sometimes working on one of them over a few weeks. Of course, I could change my customs (well, actually my template for the weekly review) to utilize headlines. That would have the added benefit of having a good place to clock my tasks for the week. A drawback is that some things are really “projects”, taking more than one week, so then I’d have them split to many headlines, each for a particular week’s portion of the project. This might be a good thing, though!

Funny thing is, I started writing this post with a clear goal in mind – to write a short Elisp routine to sum up my estimates in the format I use. Now that I have written about it, changing my template to use “proper” Org mode tasks seems a better idea – for example, I could have more than two states (like TODO, DONE, CANCELED and perhaps more), while checkboxes only have two. On the other hand, I’d like to show (again!) how easy it is to mold Emacs to my specific needs or habits, so let’s write that code anyway, just for fun.

Here is the format of my list.

1. [ ] Find that box in the cellar (20')
2. [ ] Write an email to an old friend (10')
3. [ ] Research vacation destinations (45')
4. [ ] Set up a reminder app for my phone (5')

So, here is what I need: start with the line the point is on, for each line find a number with an apostrophe (which should actually be a prime symbol, but I don’t want to bother with Unicode here), and sum up these numbers, stopping on the last line where such a number can be found.

So, let’s get to it!

(require 'cl-lib)
(defun sum-plain-list-estimates (&optional interactive)
  "Sum the estimates (in parens, in minutes) starting on this line."
  (interactive "p")
  (save-excursion
    (let ((total 0))
      (while (let* ((line (buffer-substring (line-beginning-position)
                                            (line-end-position)))
                    (estimate (when (string-match "(\\([0-9]+\\)')"
                                                  line)
                                (string-to-number
                                 (match-string 1 line)))))
               (when estimate
                 (cl-incf total estimate)))
        (forward-line))
      (when interactive
        (message "Total minutes: %d" total))
      total)))

The coolest thing about this code is that it took me less than 15 minutes to write! (And this time I made a point of not asking LLMs for help.) Of course, speed like this comes with a bit of experience, but it still shows insanely flexible and extensible Emacs is.

One thing I’d like to mention about my code is the use of the interactive parameter. It is a well-known trick to check if the function was called interactively or from Elisp, which allows me not to pollute the echo area if I ever want to call my little function programmatically, but on the other hand make it possible to pretend that it was called interactively by explicitly passing a non-nil argument to it.

That’s it for today! If you feel jealous and want to learn how to extend Emacs like this to adapt it to your specific needs, let me remind you (as usual) that a great starting point is the late Robert J. Chassell’s fantastic Introduction to programming in Emacs Lisp, and that I also wrote a little book about Emacs Lisp, as sort of a spiritual sequel to it. Happy Elisp coding!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode