[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, 25 Aug 2017 18:10:31 +0100 |
User-agent: |
mu4e 0.9.19; emacs 26.0.50 |
Nicolas Goaziou <address@hidden> writes:
> Hello,
>
> Stig Brautaset <address@hidden> 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.