From: "Štěpán Němec" <stepnem@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Lars Ingebrigtsen <larsi@gnus.org>,
Stefan Monnier <monnier@iro.umontreal.ca>,
17871@debbugs.gnu.org
Subject: bug#17871: 24.4.50; (elisp) `Core Advising Primitives': interactive spec as function?
Date: Mon, 05 Aug 2019 10:44:19 +0200 [thread overview]
Message-ID: <87o914knmk.fsf@gmail.com> (raw)
In-Reply-To: <87o914xh50.fsf@web.de> (Michael Heerdegen's message of "Mon, 05 Aug 2019 08:26:03 +0200")
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. Štěpán'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ïve 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))
--
Štěpán
next prev parent reply other threads:[~2019-08-05 8:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-29 14:13 bug#17871: 24.4.50; (elisp) `Core Advising Primitives': interactive spec as function? Drew Adams
2014-06-29 15:01 ` Michael Heerdegen
2014-06-29 15:52 ` Drew Adams
2014-06-29 22:03 ` Stefan Monnier
2014-06-29 23:49 ` Drew Adams
2014-06-30 20:48 ` Michael Heerdegen
2019-08-04 12:06 ` Lars Ingebrigtsen
2019-08-04 12:45 ` Michael Heerdegen
2019-08-04 12:56 ` Lars Ingebrigtsen
2019-08-04 15:15 ` Štěpán Němec
2019-08-05 6:26 ` Michael Heerdegen
2019-08-05 8:44 ` Štěpán Němec [this message]
2019-08-05 9:21 ` Lars Ingebrigtsen
2019-08-18 12:26 ` Michael Heerdegen
2019-08-18 13:32 ` Štěpán Němec
2019-08-18 23:06 ` Lars Ingebrigtsen
2019-08-18 23:50 ` Štěpán Němec
2019-08-19 0:35 ` Drew Adams
2019-08-20 21:49 ` Juri Linkov
2019-08-20 22:44 ` Štěpán Němec
2019-08-21 7:01 ` Stefan Monnier
2019-08-21 8:17 ` Štěpán Němec
2019-08-25 15:51 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o914knmk.fsf@gmail.com \
--to=stepnem@gmail.com \
--cc=17871@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.