[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using variable names in a macro
From: |
Narendra Joshi |
Subject: |
Re: Using variable names in a macro |
Date: |
Mon, 11 Dec 2017 19:37:25 +0530 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) |
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Narendra Joshi <narendraj9@gmail.com> writes:
>
>> Can you share an example please? :)
>
> If you want to go with anonymous functions, `letrec' is perfect here
> (`cl-labels' would work as well and avoid the need to `funcall'):
>
> #+begin_src emacs-lisp
> ;; -*- lexical-binding: t -*-
>
> (defun my-do-when-idle (f g interval)
> "Call F when idle for INTERVAL seconds and then G when there is activity."
> (letrec ((run-timer-fun (lambda () (run-with-idle-timer
> interval nil
> (lambda ()
> (funcall f)
> (add-hook 'post-command-hook
> activity-fun)))))
> (activity-fun (lambda ()
> (remove-hook 'post-command-hook activity-fun)
> (funcall g)
> (funcall run-timer-fun))))
> (funcall run-timer-fun)))
> #+end_src
Perfect. `letrec` makes it very simple! :) Thanks a lot! :)
>
> I've changed the order in the `activity-fun' to run `remove-hook' first,
> so that you get a sane behavior when running G gives an error.
Makes sense! :)
Best,
--
Narendra Joshi