From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Newsgroups: gmane.emacs.bugs Subject: bug#17871: 24.4.50; (elisp) `Core Advising Primitives': interactive spec as function? Date: Mon, 05 Aug 2019 10:44:19 +0200 Message-ID: <87o914knmk.fsf@gmail.com> References: <400906ac-35f1-48e4-8df9-8e65b340209b@default> <87vbrjdajs.fsf@web.de> <82178260-247b-4653-85db-d6586480419e@default> <87d2dqdsyj.fsf@web.de> <8736ihb0ds.fsf@mouse.gnus.org> <87d0hl3xqx.fsf@web.de> <878ss99jhi.fsf@mouse.gnus.org> <87o914xh50.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="200467"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Lars Ingebrigtsen , Stefan Monnier , 17871@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 05 10:46:02 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1huYcy-000q0Q-Oo for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Aug 2019 10:46:01 +0200 Original-Received: from localhost ([::1]:51766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1huYcx-00083S-C0 for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Aug 2019 04:45:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52831) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1huYc4-00070Q-24 for bug-gnu-emacs@gnu.org; Mon, 05 Aug 2019 04:45:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1huYc2-0006Qa-SF for bug-gnu-emacs@gnu.org; Mon, 05 Aug 2019 04:45:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53993) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1huYc2-0006Pg-MD for bug-gnu-emacs@gnu.org; Mon, 05 Aug 2019 04:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1huYc2-0004zZ-Gn for bug-gnu-emacs@gnu.org; Mon, 05 Aug 2019 04:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 05 Aug 2019 08:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17871 X-GNU-PR-Package: emacs Original-Received: via spool by 17871-submit@debbugs.gnu.org id=B17871.156499467019129 (code B ref 17871); Mon, 05 Aug 2019 08:45:02 +0000 Original-Received: (at 17871) by debbugs.gnu.org; 5 Aug 2019 08:44:30 +0000 Original-Received: from localhost ([127.0.0.1]:34581 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1huYbV-0004yT-MA for submit@debbugs.gnu.org; Mon, 05 Aug 2019 04:44:29 -0400 Original-Received: from mail-wm1-f66.google.com ([209.85.128.66]:53790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1huYbT-0004yF-47 for 17871@debbugs.gnu.org; Mon, 05 Aug 2019 04:44:27 -0400 Original-Received: by mail-wm1-f66.google.com with SMTP id x15so73892963wmj.3 for <17871@debbugs.gnu.org>; Mon, 05 Aug 2019 01:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-transfer-encoding; bh=0go8NEMEmZIc10+BzSCMugSdUG8p/vRbVQtYPAa0wM8=; b=uZT0/jPbdfJvL50DLYbHuK8d8K5q0JU4qwxTpvDNEYvNNXcTJ7xLjR6sqfPFQs46qH ZfRvf/sKY8R4OFcj4UomyVubY+nCUyX3wB2LYIjqjmTUqwvYtcfElQE5FmVYA3R7C2CN rn3P9mt58aTxLDY4JHvtYdxsy6xggQ++pEPdB8c+qbOw2KhnSJiOYNBNhftB2xFh8oRO AoPvLES3Q8WeubnT8IRSgQ24A+CGZQd64S0HfT+t5pXyQbfRXbTj3xvQ80/2YUOzEeNY yRJmR1EO2lNBjT/huOEhfUgds6oic8bBpaetVW4bXKc54Ek2NvIqbbZQDUybxE/8AxkL 375w== 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:in-reply-to:references :user-agent:date:message-id:mime-version:content-transfer-encoding; bh=0go8NEMEmZIc10+BzSCMugSdUG8p/vRbVQtYPAa0wM8=; b=XYLXGyLgogP3r7FKy7zCPiIdlPz7R4ESDTAzFCymy4KzCXAnuEB2uSZ+l0IuS2oevd abHO03FnHrr8arINrLndBZGBw2UVfyVaCKezON63v5A6q+vGKKXpdwz8wy2VC89ZczET /C/82TVy8d+OOa1J7LZXTxSVSpwJs4x45OR3PwrSMPyjDQl0/rMNd8SlleyeOqEQsxz3 8M0E/zvT4a81MjbI7Qdh51WdRf5u21K+HIAM6ogO0PMNcvDVa5WR01E14jB529mwcTI9 KfxTuKdoNQeYA5CJFfRQO85salyn1y8EOJu2yS0icqssI189pvBhtIp0JRWDtNQhuSiW QkjA== X-Gm-Message-State: APjAAAVnAA23gi/lMHwYW08kiFutQhhCE+OeKne5dspX1Y0jDOZzs64S Wg4B9YV6TchOKz51vCQ4Mlg= X-Google-Smtp-Source: APXvYqyVm9h2ZBvATTljyfyaehHv9fQnpVJ4eWur1zhlTytxL4zETxQxfvG0xTTNLGl1FsyvJ/blZQ== X-Received: by 2002:a1c:c1c1:: with SMTP id r184mr17416008wmf.9.1564994661390; Mon, 05 Aug 2019 01:44:21 -0700 (PDT) Original-Received: from localhost ([185.112.167.114]) by smtp.gmail.com with ESMTPSA id n12sm87328245wmc.24.2019.08.05.01.44.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 01:44:20 -0700 (PDT) In-Reply-To: <87o914xh50.fsf@web.de> (Michael Heerdegen's message of "Mon, 05 Aug 2019 08:26:03 +0200") 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: 209.51.188.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:164617 Archived-At: On Mon, 05 Aug 2019 08:26:03 +0200 Michael Heerdegen wrote: > [...] the following typical use cases: > > (1) Changing how input is read for a single command. =C5=A0t=C4=9Bp=C3= =A1n's example > is such a thing. Make individual commands use helm or ido or icicles, > or single command not use helm or ido or icicles although the according > mode is turned on, is a use case. > > (2) Enhance a command to accept an additional argument. The interactive > form of the :around advice will reuse the interactive form of the > original command to read in the arguments the original command accepts, > read in the additional argument, and return the combined list. > > (3) Make input reading saver: If certain input for a command is > potentially dangerous or error-prone, one could change it to add tests/ > ask for confirmation, or run it in a loop y (confirm) n (abort) r > (retry, give new input). Thank you for the write-up! I for one would really appreciate if all of that went into the manual, ideally with examples (not only one). I was now able to simplify my originally overcomplicated real-life example to the following, but it wasn't as easy as I would have liked back then to figure it out perusing the existing documentation (I had to look at the code as well): Say you use `ivy-mode' for minibuffer completion, as well as `ivy-prescient-mode' from the `prescient' package, which modifies the way ivy sorts completion candidates. But there is a command `my-command' where `ivy-prescient-mode' really gets in the way instead of helping, so you want to disable it for that single command. Unfortunately, the following na=C3=AFve version does not work: (defun my-no-prescient-advice (orig &rest args) (let ((enabled ivy-prescient-mode)) (unwind-protect (progn (when enabled (ivy-prescient-mode -1)) (apply orig args)) (when enabled (ivy-prescient-mode 1))))) (advice-add 'my-command :around #'my-no-prescient-advice) because it has no effect on the `interactive' form of `my-command' [BTW, I find this very strange, so if that's really a feature it should IMO be mentioned prominently in the documentation]. You have to do something like the following instead: (defun my-no-prescient-advice (orig &rest args) (interactive (lambda (spec) (let ((enabled ivy-prescient-mode)) (unwind-protect (progn (when enabled (ivy-prescient-mode -1)) (advice-eval-interactive-spec spec)) (when enabled (ivy-prescient-mode 1)))))) (apply orig args)) --=20 =C5=A0t=C4=9Bp=C3=A1n