From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Narendra Joshi Newsgroups: gmane.emacs.help Subject: Re: Using variable names in a macro Date: Mon, 11 Dec 2017 19:37:25 +0530 Message-ID: <87609djr36.fsf@gmail.com> References: <87r2s3aoks.fsf@gmail.com> <874loyx1ne.fsf@web.de> <87k1xuod9x.fsf@gmail.com> <87bmj6cwu3.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1513002126 6755 195.159.176.226 (11 Dec 2017 14:22:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Dec 2017 14:22:06 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: help-gnu-emacs To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 11 15:22:00 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 1eOOxy-0001OJ-J3 for geh-help-gnu-emacs@m.gmane.org; Mon, 11 Dec 2017 15:21:58 +0100 Original-Received: from localhost ([::1]:53437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOOy5-0005Cg-JP for geh-help-gnu-emacs@m.gmane.org; Mon, 11 Dec 2017 09:22:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOOk3-0001Qf-Rb for help-gnu-emacs@gnu.org; Mon, 11 Dec 2017 09:07:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOOk0-0006fI-Kc for help-gnu-emacs@gnu.org; Mon, 11 Dec 2017 09:07:35 -0500 Original-Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:32910) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOOk0-0006ec-EB for help-gnu-emacs@gnu.org; Mon, 11 Dec 2017 09:07:32 -0500 Original-Received: by mail-pf0-x22c.google.com with SMTP id y89so11619955pfk.0 for ; Mon, 11 Dec 2017 06:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=kaHNVmEZ+wRbhWisx0WkDpeEKbg4zcp6gWuGrIElnEo=; b=U0jpTYpsQbA/7NrkogUF2vTPbK7NXts1YkNEMR6q0Vbv2a8t3KmWfnbnd61fvv7YQm 8ig1gJYK3ZhJzRclP+Rcaa0Z8ASObaMp0k7f1pbQAi7qLzD9y9XEEnP+/fL14DLEGuF1 pFTfULBFlqAYt30UYtSpiKCTqJcxrCsI8U/F5Hxe7MWUmL9nnBVS/KqrPn6kxT8KMMs7 xeMQ7gq6BghVNxLshmclCwj4i4jEqUypzOq5bVHtk/9nXqiKUJiYC0yzSKIcoWZROrts MmDs4vwivAUC7RL4huSonGNgJIL/6yxpb/6+03sRZUi4GydZhptXZzzP8ul17Je8WAVP e9kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=kaHNVmEZ+wRbhWisx0WkDpeEKbg4zcp6gWuGrIElnEo=; b=RdlbV1DyZ0I0BtMtObOPtds1BaPa3E4VuUS6Bngfo+55RZEJtuFXNhl1MP8maDQoxD Bq5juWscZNe1hSLhqJD8g56aBntCX/rdO/HWbNd7V0gNPGjrrxFp0ZRg5X/vgL04slFq Wwwzha7yFxtkl/46CWK3DvFJg/ufe9FgiBtX2eSBwHy1byqsBPjd05PVF1KGl8kW60ao FwJQIkVDjZsoriVKVxJB3FGk9X2g4/PPTiqshI//FKy5Sf/AnSxy2I6ImtSuCmUHKbZ7 Tt3yTq/NKHGZ07q8ZyJi5bAAc5P0uGZBQClCSQp6qZw3SO0xANsp3FYyoYO/KoiNoa5y cysQ== X-Gm-Message-State: AKGB3mIeRYBu6gURJcWX9c8lV+6nPbQHRNY3wUEjFL1BQddnBBGRFKzU l6oInn2GR964yzdkm9n7Z7It X-Google-Smtp-Source: ACJfBoum20zugKL0g7xKZja0WJv0AA1X3B6W3KQ/LFVzarLcLbAf/7NAIdQpZJruxU0AK/9N+l4a2g== X-Received: by 10.101.101.211 with SMTP id y19mr458288pgv.138.1513001250927; Mon, 11 Dec 2017 06:07:30 -0800 (PST) Original-Received: from vicarie ([1.23.208.249]) by smtp.gmail.com with ESMTPSA id l14sm20345674pgn.9.2017.12.11.06.07.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Dec 2017 06:07:29 -0800 (PST) In-Reply-To: <87bmj6cwu3.fsf@web.de> (Michael Heerdegen's message of "Sun, 10 Dec 2017 18:32:52 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22c 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:115333 Archived-At: Michael Heerdegen writes: > 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 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