From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: FYI: with-org-today-date macro, helps with testing Date: Sat, 29 Jul 2017 16:26:23 -0400 Message-ID: <87inibouq8.fsf@kyleam.com> References: <87fudfepqo.fsf@alphapapa.net> <87lgn7palq.fsf@kyleam.com> <877eyrvxhr.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbYJh-0005qp-Bv for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 16:26:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbYJe-000580-7c for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 16:26:29 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:57487 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dbYJe-00057C-1r for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 16:26:26 -0400 In-Reply-To: <877eyrvxhr.fsf@alphapapa.net> 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: Adam Porter , emacs-orgmode@gnu.org Adam Porter writes: > Kyle Meyer writes: [...] >> You should be able to simplify the macro body to >> >> `(cl-letf (((symbol-function 'org-today) (lambda () (date-to-day ,date)))) >> ,@body) > > Hi Kyle, > > I tried that, but it didn't work, so I had to come up with this uglier > one. I couldn't figure out why, but with cl-letf, the redefined > function didn't seem to persist deeper in the tree of function calls, > only to the first level. Maybe I did something wrong, but all I know > now is that at least this works. :) On my end, (defmacro with-org-today-date (date &rest body) `(cl-letf (((symbol-function 'org-today) (lambda () (date-to-day ,date)))) ,@body)) (with-org-today-date "2017-07-05 00:00" (let ((org-agenda-files (list "~/test.org")) (org-agenda-span 'day)) (org-agenda-list nil))) produces the same result as your original macro. -- Kyle