From: Stig Brautaset <stig@brautaset.org>
To: emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: Conditional summing in column-mode?
Date: Fri, 25 Aug 2017 18:10:31 +0100 [thread overview]
Message-ID: <m2wp5rd14o.fsf@brautaset.org> (raw)
In-Reply-To: <87bmn4ytce.fsf@nicolasgoaziou.fr>
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Stig Brautaset <stig@brautaset.org> writes:
>
>> I have the following column-mode defined in =~/org/Holidays.org=:
>>
>> #+BEGIN_SRC org
>> ,#+COLUMNS: %TIMESTAMP(When) %ITEM(What) %CONFIRMED(Confirmed?){X/} %DAYS(Days){+}
>> ,#+Confirmed_ALL: "[ ]" "[X]"
>> ,#+TODO: TODO | DONE CANCELLED
>> #+END_SRC
>>
>> Is it possible to have the =%DAYS(Days){+}= part only sum up rows that
>> have an =[X]= in their =Confirmed?= property?
>
> Not out of the box. But you could write a function creating and updating
> another property, e.g., CHECKED_DAYS and have columns view display this
> instead.
Thank you! That's a great idea. I've managed to come up with the
following, which works interactively:
#+BEGIN_SRC emacs-lisp
(defun sb/org-calc-confirmed-days ()
"For an entry with both a `CONFIRMED' and `DAYS' property, calculate `CONFIRMED_DAYS'"
(let ((days (org-entry-get nil "DAYS"))
(confirmed (org-entry-get nil "CONFIRMED")))
(when (and days
(string= "[X]" confirmed))
(org-entry-put nil "CONFIRMED_DAYS" days))))
(defun sb/org-map-confirmed-days ()
"Map over entries and calculate confirmed days"
(interactive)
(org-map-entries #'sb/org-calc-confirmed-days))
#+END_SRC
However, I would like to add an advice around =org-columns-compute-all=
to run the =sb/org-map-confirmed-days= function, and this I have not
been successful at. I've tried doing this:
: (add-function :before org-columns-compute-all #'sb/org-map-confirmed-days)
However, I keep getting the following error:
: Use of gv-ref probably requires lexical-binding
: advice--add-function: Symbol’s value as variable is void: org-columns-compute-all
I would appreciate if anyone has any insight into solving this.
Stig
PS: I'm using Emacs and Org both installed from Git, on macOS.
next prev parent reply other threads:[~2017-08-25 17:10 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 [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2wp5rd14o.fsf@brautaset.org \
--to=stig@brautaset.org \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.