From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#33601: 26; Add macro `with-hook-added' Date: Tue, 4 Dec 2018 11:18:29 -0800 (PST) Message-ID: References: <> <<20181204184614.2049.qmail@mail.muc.de>> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1543951037 28962 195.159.176.226 (4 Dec 2018 19:17:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Dec 2018 19:17:17 +0000 (UTC) Cc: 33601@debbugs.gnu.org To: Alan Mackenzie , Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Dec 04 20:17:13 2018 Return-path: Envelope-to: geb-bug-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 1gUGC0-0007Qk-0Z for geb-bug-gnu-emacs@m.gmane.org; Tue, 04 Dec 2018 20:17:12 +0100 Original-Received: from localhost ([::1]:58663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUGE6-0002dn-CX for geb-bug-gnu-emacs@m.gmane.org; Tue, 04 Dec 2018 14:19:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUGDq-0002YT-VF for bug-gnu-emacs@gnu.org; Tue, 04 Dec 2018 14:19:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUGDo-0001o4-6q for bug-gnu-emacs@gnu.org; Tue, 04 Dec 2018 14:19:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56718) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUGDo-0001nw-2e for bug-gnu-emacs@gnu.org; Tue, 04 Dec 2018 14:19:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gUGDm-0007d0-Jq for bug-gnu-emacs@gnu.org; Tue, 04 Dec 2018 14:19:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 04 Dec 2018 19:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33601 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 33601-submit@debbugs.gnu.org id=B33601.154395112129287 (code B ref 33601); Tue, 04 Dec 2018 19:19:02 +0000 Original-Received: (at 33601) by debbugs.gnu.org; 4 Dec 2018 19:18:41 +0000 Original-Received: from localhost ([127.0.0.1]:60976 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gUGDR-0007cI-5F for submit@debbugs.gnu.org; Tue, 04 Dec 2018 14:18:41 -0500 Original-Received: from aserp2130.oracle.com ([141.146.126.79]:51102) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gUGDP-0007c3-2A for 33601@debbugs.gnu.org; Tue, 04 Dec 2018 14:18:39 -0500 Original-Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB4JED94000843; Tue, 4 Dec 2018 19:18:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=IGi2qIEDlzn3tfYoKfxKan6rlXvYY81XMlMdIsZhE5o=; b=TJsosvUol1htlLaPk1FlZ42SHwyjRSHQk/1qvVWrXAQo+enK54FDvA3QS/PxFxFnZLrJ G8Ng4h5UDNMiRwJ1qb/uZuX5N84w+OAJE6BuCjk38l6Xxb2NADLdTjVI8ykgiFyYyZ4z lsX7V2y7W5/8MZyIk60ZiE8wFG+FqjVq8pY/3/F2c4+xq/Ps7l2Lo4SaF0oS5xv0haDg CMOmxpp1lmU+IYsHczmvJdMnCBnezPDCDF1maWBGuHElVSTfqPeT4rrINhgRqk9MaEx+ M0mAEkfuBAZjiHN+o5j2kun4SvPd8K3+GdxPi3bcuaEfvHQuXOyF6Nvuq3UKw1j9qzRP eg== Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2p3ftf2ckk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Dec 2018 19:18:32 +0000 Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wB4JIUrD020308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Dec 2018 19:18:31 GMT Original-Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wB4JIUM7030002; Tue, 4 Dec 2018 19:18:30 GMT In-Reply-To: <<20181204184614.2049.qmail@mail.muc.de>> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4771.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9097 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812040164 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153075 Archived-At: > > Enhancement request: Please consider adding a macro such as this, to > > facilitate temporary use of a hook function. >=20 > > (defmacro with-hook-added (hook function &rest body) > > "Evaluate forms in BODY with FUNCTION added to HOOK, then remove FUNC= TION." > > (declare (indent 1) (debug t)) > > `(unwind-protect (progn (add-hook ',hook ',function) ,@body) > > (remove-hook ',hook ',function))) >=20 > Just a big point: you need to test whether FUNCTION is already on HOOK > at the start, and if so, not remove it at the end. Hi Alan, A big point? Need to? That wasn't the behavior I had in mind for this, but it's another possibility. I intended to provide only for the behavior of always removing at the end. There are in fact several different possibilities for such a macro. We could provide also for `add-hook' args APPEND and LOCAL. I left that out as well. Choices: 1. Provide a single macro for all such possibilities, with 3 (mandatory) args for APPEND, LOCAL and whether to remove FUNCTION at the end if it was already present at the outset. 2. Provide multiple macros, each specific for a given case. #2 would mean 8 macros, to cover all the combinations (nil or t for each of the 3 args). Another possibility would be to accept a single arg for the BODY code, instead of that being a &rest parameter, and so be able to provide those 3 behavior-specifying args as optional. In that case, we'd want to decide on the best order among those args, e.g., based on which we expect to be used most often. I'm not sure what the right approach is. I think the most common use case would be the one I wrote up (but I don't know that): . Always remove FUNCTION at the end . Prepend, not append. . Global, not local.