emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Stig Brautaset <stig@brautaset.org>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: Conditional summing in column-mode?
Date: Fri, 01 Sep 2017 01:07:07 +0100	[thread overview]
Message-ID: <m2efrrjn84.fsf@brautaset.org> (raw)
In-Reply-To: <87tw0qrgqd.fsf@nicolasgoaziou.fr>


Nicolas Goaziou <mail@nicolasgoaziou.fr> 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	other threads:[~2017-09-01  0:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 15:49 Conditional summing in column-mode? Stig Brautaset
2017-08-25  7:55 ` Nicolas Goaziou
2017-08-25 17:10   ` Stig Brautaset
2017-08-25 19:55     ` Nicolas Goaziou
2017-08-28 10:41       ` Stig Brautaset
2017-08-29  7:11         ` Nicolas Goaziou
2017-09-01  0:07           ` Stig Brautaset [this message]
2017-09-01 21:29             ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2efrrjn84.fsf@brautaset.org \
    --to=stig@brautaset.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).