emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Conditional summing in column-mode?


From: Stig Brautaset
Subject: Re: [O] Conditional summing in column-mode?
Date: Fri, 01 Sep 2017 01:07:07 +0100
User-agent: mu4e 0.9.19; emacs 26.0.50

Nicolas Goaziou <address@hidden> writes:

>> Is there a hook I can use that is called before the property values
>> are extracted? (I wasn't able to find one.)
>
> There isn't.
>
> But here is an idea: `org-columns-summary-types' could also accept
> entries like:
>
>   (LABEL SUMMARIZE COLLECT)
>
> where COLLECT is a function called on each summarized entry. SUMMARIZE
> is applied on the values returned by COLLECT. When not provided, COLLECT
> default to `org-entry-get' as it is the case already.
>
> WDYT?

I think I like it. So I could then do something like:

    (defun sb/org-collect-confirmed-days ()
      "Return `DAYS' for `CONFIRMED' entries, otherwise return 0"
      (let ((days (org-entry-get nil "DAYS"))
            (confirmed (org-entry-get nil "CONFIRMED")))
        (if (and days (string= "[X]" confirmed))
            days
          "0")))

    (setq org-columns-summary-types
          '(("X+" org-columns--summary-sum sb/org-collect-confirmed-days)))


That seems quite elegant! I guess the COLLECT function would be called
in `org-agenda-colview-summarize' such that the existing summary
functions would not need to change?

Though, there will then be a tight coupling between the "X+" label and
the column name, which is not ideal. Perhaps the COLLECT function could
(optionally?) take the column name (or the whole column spec) as an
argument so we could do something like:

    (defun sb/org-collect-confirmed-things (thing)
      "Return `THING for `CONFIRMED' entries, otherwise return 0"
      (let ((thing (org-entry-get nil thing))
            (confirmed (org-entry-get nil "CONFIRMED")))
        (if (and thing (string= "[X]" confirmed))
            thing
          "0")))

Then we could use =X+= to calculate both confirmed Days and Bananas:

    #+COLUMNS: %TIMESTAMP(When) %ITEM(What) %CONFIRMED(Confirmed?){X/} 
%Days(X+) %Bananas(X+)

Does this make sense?

I don't mind having a go at adding support for this, though I admit I'm
slightly terrified of the code in `org-agenda-colview-summarize' :-)


Stig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]