emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: emacs-orgmode@gnu.org
Subject: Re: FYI: with-org-today-date macro, helps with testing
Date: Sat, 29 Jul 2017 14:44:48 -0500	[thread overview]
Message-ID: <877eyrvxhr.fsf@alphapapa.net> (raw)
In-Reply-To: 87lgn7palq.fsf@kyleam.com

Kyle Meyer <kyle@kyleam.com> writes:

> Adam Porter <adam@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	other threads:[~2017-07-29 19:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-29  6:11 FYI: with-org-today-date macro, helps with testing Adam Porter
2017-07-29 14:43 ` Kyle Meyer
2017-07-29 19:44   ` Adam Porter [this message]
2017-07-29 20:26     ` Kyle Meyer
2017-07-29 23:03       ` Adam Porter
2018-10-23 20:56         ` Samuel Wales

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877eyrvxhr.fsf@alphapapa.net \
    --to=adam@alphapapa.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).