From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: Using variable names in a macro Date: Sun, 10 Dec 2017 18:32:52 +0100 Message-ID: <87bmj6cwu3.fsf@web.de> References: <87r2s3aoks.fsf@gmail.com> <874loyx1ne.fsf@web.de> <87k1xuod9x.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1512927207 10592 195.159.176.226 (10 Dec 2017 17:33:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 10 Dec 2017 17:33:27 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs To: Narendra Joshi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 10 18:33:24 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eO5Tf-0002YT-H7 for geh-help-gnu-emacs@m.gmane.org; Sun, 10 Dec 2017 18:33:23 +0100 Original-Received: from localhost ([::1]:45422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eO5Tm-0002NZ-Nq for geh-help-gnu-emacs@m.gmane.org; Sun, 10 Dec 2017 12:33:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eO5TH-0002NS-PY for help-gnu-emacs@gnu.org; Sun, 10 Dec 2017 12:33:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eO5TE-0004mC-M9 for help-gnu-emacs@gnu.org; Sun, 10 Dec 2017 12:32:59 -0500 Original-Received: from mout.web.de ([212.227.15.3]:55290) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eO5TE-0004lR-CI for help-gnu-emacs@gnu.org; Sun, 10 Dec 2017 12:32:56 -0500 Original-Received: from drachen.dragon ([92.74.165.17]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lir9R-1etpii1DDx-00cua3; Sun, 10 Dec 2017 18:32:53 +0100 In-Reply-To: <87k1xuod9x.fsf@gmail.com> (Narendra Joshi's message of "Sun, 10 Dec 2017 20:12:18 +0530") X-Provags-ID: V03:K0:MgiXxsGAgh3jy1b9PfeEm1lGxI068BtiDo1LzhXVZj+edscEaQK +xngb419hZQzdTCv14E0Jr461uDGsjpqEa+D+jXa/5aokcT4O2ohl9iD/TZUvRDcEsWlL6i iypkcW8QAT/7IwkcRezAKjLUcPSA1Orc9MjAoYxjoElE/jCPWMcn9BRMQflgiMHx5EivchC vfXKaeF5k/obkdtYhKijg== X-UI-Out-Filterresults: notjunk:1;V01:K0:sn/sCdrpO7Y=:iQI+IjFzzOq8BC7nUgWnyJ 0JlC5Bini9ZvhrTpdmuZlqffZo1VcQRZG+pAO0zra1IF8d7n3UG3/MjQ/aaMGxfvGTt3gcoiV 3jvGVfXErB/a/uXv3DbMymED4+dNvnGL6dRKBBckqiJwx8dEC1jdF1f6IZ1Tgd5g+hxyvrwQk XAdskJTrjOnGoUDJMzyb3LOLVVbAeBNXtoi9ncGNvyzwYP9ikGsg6xUjlqFoEYY3Q1dav893V Cv/8PtPZob0S/G4aqTndmyAm84vlOsKawUvbrsTfjjfcDM7X+rH76UTD/iGszo2ES1unfhvYp NaCtiljcqgt069Ldm6mJV05phvRzarLWKN+b5MbpiwQYvLA71FoyjzYM5S0g75dzLhbE83ed+ sCG3nT7KzinNajhY4kR9KVGp0D0dB3gzsC1QYjd0v6XtK0+HZxMYyW53Yc3SlqOZyoaYThScQ zTY5NwTKC82TopYe+v6wYXmMkJXlMYE13lodEF28DMzUA+nY67mF6BHPT0RTQJWXKygTr0tu1 sr8hoAWClkPlmEipgimSKb8TVEg8ZfvVp5y17LaDUJkIUeC9z3P3kahb27yydVz/hy2qNaOhi xbJ287Chj5ho2Yg85MMcFiziFahZIAfEFdYz53jbtpFbMDqCOrvWgYvcOjLKCs8EAnbLpEiBZ qG7IIS289K1xyOE/XU0Xmqr5J/KI7yh6eAMwh5TzlzefhJ0CRPQPcxEndMMUjiaSeFqncxvO9 Gw1RfFZBWEmthSIgYk3FpukUAFe2mMBlVFWgiq3pMRySeBtQyg4RfSZSzdEhLqhsy4J5x8KJ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115328 Archived-At: Narendra Joshi 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 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. A short test: #+begin_src emacs-lisp (my-do-when-idle (lambda () (message "%s" (current-time-string))) (lambda () (message "Stopping timer")) 5) #+end_src Michael.