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: Using variable names in a macro Date: Sat, 09 Dec 2017 21:19:39 +0530 Message-ID: <87r2s3aoks.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1512834614 29318 195.159.176.226 (9 Dec 2017 15:50:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 9 Dec 2017 15:50:14 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 09 16:50:11 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 1eNhOE-0007Uo-PP for geh-help-gnu-emacs@m.gmane.org; Sat, 09 Dec 2017 16:50:10 +0100 Original-Received: from localhost ([::1]:41776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNhOM-0001Uc-3v for geh-help-gnu-emacs@m.gmane.org; Sat, 09 Dec 2017 10:50:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNhNu-0001UW-Fn for help-gnu-emacs@gnu.org; Sat, 09 Dec 2017 10:49:51 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eNhNr-0005k9-CK for help-gnu-emacs@gnu.org; Sat, 09 Dec 2017 10:49:50 -0500 Original-Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:34884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eNhNr-0005jt-6Y for help-gnu-emacs@gnu.org; Sat, 09 Dec 2017 10:49:47 -0500 Original-Received: by mail-pf0-x22c.google.com with SMTP id j124so9010280pfc.2 for ; Sat, 09 Dec 2017 07:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=hhEXP1xKZd9ftMDp7PCSQ6rYKR0F6RaVx2FACkhilsk=; b=KUMA3lil57Ub9AquQwKbE/en0tSNn0g1V0oX5MFkLhRS+A8e3U2HInSetcLIrJnhsV rQ0eFNs1VJTBYFUxIms6igwk1cpX9rERAbpLJBsc5UIUxbYly5Tba39dmYJ4etHQMXja 7FQU94NAhf3CriWzuPtS15WxFJxL5Ip9a2WKMcUodHcvS+Maxvk6vP8g0qCLdUyMueFY 9F/yyPXWkbbZ18JH3REvnSoTi7LHj+NbaCfl2CwwmXPBpnOwZwzmvB8Ja3Fx71v13qQx nOeZHHQeDvqiZd7r0GR32imK+yQzwQSbmFS0Ap61KIHGMo95ThcRFxUtzIYW6+qc3o6T YnvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=hhEXP1xKZd9ftMDp7PCSQ6rYKR0F6RaVx2FACkhilsk=; b=rotMfv0RzTxGrlPAnlsol85cIzK3B6Dk6e2CjRepumudDVt+x/xWS4ky9WeNA2HJ3b AgNVtJ83xYpZN988/7cg2UE1h01Vlhr1VEWjsUkW1WT98abgvILAJpmnTGwwvygfMGQC ZYcfJQsxxA3DgMJTsV9DLZPyLAkjKn1kV7ujxrZRDBJ0gRK0wrOl5bqD6QKx5aJiswD0 8gF9fG7ZCM/MArPSeqkY8ITwkEIqPGCCRnq38hpL0vojyq8JAP618gk1NeQxZE7D1Ylp 3etnqPFDNaSp8bnJf/KDTFrlQ2MJbhy8cyYULTg5gcZmASEGO+xL6Fqsku0g/aY5Bux3 yukw== X-Gm-Message-State: AJaThX6Nh+9lOqZb2M2oSmJm/iJd0fxqLpXY/xhSYsilNapgv39Vv3MT KbOTyVlKoxowb3ZijNetE0Ch X-Google-Smtp-Source: AGs4zMZC063/PHIteBwUiMD4hx1iVG9gkzXF2VUny/iIXEDgoM21sumNM5sHP2ghcUlSuo0jtiY6aw== X-Received: by 10.99.106.132 with SMTP id f126mr33103533pgc.403.1512834584983; Sat, 09 Dec 2017 07:49:44 -0800 (PST) Original-Received: from vicarie ([1.23.210.43]) by smtp.gmail.com with ESMTPSA id z2sm16027711pgu.17.2017.12.09.07.49.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Dec 2017 07:49:43 -0800 (PST) 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:115318 Archived-At: 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