Kyle Meyer <k...@kyleam.com> writes:

> Adam Porter <a...@alphapapa.net> 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