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: Kyle Meyer
Subject: Re: [O] FYI: with-org-today-date macro, helps with testing
Date: Sat, 29 Jul 2017 10:43:29 -0400

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)
-- 
Kyle



reply via email to

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