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 10:43:29 -0400 Message-ID: <87lgn7palq.fsf@kyleam.com> References: <87fudfepqo.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbSxv-00088i-2V for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 10:43:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbSxr-0000Iz-5s for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 10:43:39 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:52698 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 1dbSxr-0000Hn-0f for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 10:43:35 -0400 In-Reply-To: <87fudfepqo.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: > #+BEGIN_SRC elisp > (defmacro with-org-today-date (date &rest body) > "Run BODY with the `org-today' function set to return simply DATE. > DATE should be a date-time string (both date and time must be included)." > (declare (indent defun)) > `(let ((day (date-to-day ,date)) > (orig (symbol-function 'org-today))) > (unwind-protect > (progn > (fset 'org-today (lambda () day)) > ,@body) > (fset 'org-today orig)))) > #+END_SRC You should be able to simplify the macro body to `(cl-letf (((symbol-function 'org-today) (lambda () (date-to-day ,date)))) ,@body) -- Kyle