emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] FYI: with-org-today-date macro, helps with testing


From: Adam Porter
Subject: Re: [O] FYI: with-org-today-date macro, helps with testing
Date: Sat, 29 Jul 2017 14:44:48 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Kyle Meyer <address@hidden> writes:

> Adam Porter <address@hidden> 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)

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.  :)

Thanks.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]