From: Narendra Joshi <narendraj9@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Using variable names in a macro
Date: Sat, 09 Dec 2017 21:19:39 +0530 [thread overview]
Message-ID: <87r2s3aoks.fsf@gmail.com> (raw)
Hi,
I want to refactor the following macro. I use it to do things at times
when I am idle for some time and when I come back to the keyboard
eventually. For example, showing bitcoin prices when I have been idle
for some time but removing them from the mode line once I am back as it
takes a lot of space. I think there is a lot of repetition but I am not
sure how to abstract things out into variables. It would have been
simpler if an anonymous function could refer itself.
```
(defmacro do-when-idle (f g interval)
"Call F when idle for INTERVAL seconds and then G when there is activity."
`(progn
(defun ,(intern (concat "do-when-idle-"
(sha1 (format "%s-%s" f g)))) ()
(funcall ,g)
(remove-hook 'post-command-hook
#',(intern (concat "do-when-idle-"
(sha1 (format "%s-%s" f g)))))
(run-with-idle-timer ,interval
nil
(lambda ()
(funcall ,f)
(add-hook 'post-command-hook
#',(intern (concat "do-when-idle-"
(sha1 (format "%s-%s" f g))))))))
(run-with-idle-timer ,interval
nil
(lambda ()
(funcall ,f)
(add-hook 'post-command-hook
#',(intern (concat "do-when-idle-"
(sha1 (format "%s-%s" f g)))))))))
```
Best,
--
Narendra Joshi
next reply other threads:[~2017-12-09 15:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-09 15:49 Narendra Joshi [this message]
2017-12-10 11:28 ` Using variable names in a macro Michael Heerdegen
2017-12-10 14:42 ` Narendra Joshi
2017-12-10 17:32 ` Michael Heerdegen
2017-12-11 14:07 ` Narendra Joshi
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.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r2s3aoks.fsf@gmail.com \
--to=narendraj9@gmail.com \
--cc=help-gnu-emacs@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.
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).