From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stig Brautaset Subject: Re: Conditional summing in column-mode? Date: Fri, 25 Aug 2017 18:10:31 +0100 Message-ID: References: <87bmn4ytce.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlI80-0008JB-5G for emacs-orgmode@gnu.org; Fri, 25 Aug 2017 13:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlI7w-0003xf-UL for emacs-orgmode@gnu.org; Fri, 25 Aug 2017 13:10:40 -0400 Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]:45706) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlI7w-0003vg-Hs for emacs-orgmode@gnu.org; Fri, 25 Aug 2017 13:10:36 -0400 Received: from localhost (unknown [185.59.181.102]) (Authenticated sender: mailbox@brautaset.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 1378E41C092 for ; Fri, 25 Aug 2017 19:10:33 +0200 (CEST) In-reply-to: <87bmn4ytce.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-org list Nicolas Goaziou writes: > Hello, > > Stig Brautaset 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.