* Advising interactive commands
@ 2024-07-23 0:16 Ag Ibragimov
2024-07-23 7:52 ` Andreas Schwab
0 siblings, 1 reply; 2+ messages in thread
From: Ag Ibragimov @ 2024-07-23 0:16 UTC (permalink / raw)
To: emacs-devel
Can someone please clarify my confusion about advising interactive commands? For some reason, I am unable to advise commands with interactive parameters. So, check this out:
(defun my-command (file)
(interactive (list (read-file-name "Find file: "))))
When called, it prompts to select a file, alright?
Now, if I do this:
(defun my-command-override ()
(message "running override"))
(advice-add 'my-command :override 'my-command-override)
I expect my new function to run instead, right? And indeed, this works:
(funcall 'my-command) ;; immediately shows the message
However, for whatever reason the following doesn't:
(call-interactively 'my-command)
Meaning, that it doesn't fully override it when called from M-x menu. I mean, it would prompt for the file but only after that it would call my-command-override. Why is that? Is this expected? If it is, how do you advise such commands so they don't show prompts for their parameters?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Advising interactive commands
2024-07-23 0:16 Advising interactive commands Ag Ibragimov
@ 2024-07-23 7:52 ` Andreas Schwab
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2024-07-23 7:52 UTC (permalink / raw)
To: Ag Ibragimov; +Cc: emacs-devel
This paragraph in the doc string of add-function applies here:
If one of FUNCTION or OLDFUN is interactive, then the resulting function
is also interactive. There are 3 cases:
- FUNCTION is not interactive: the interactive spec of OLDFUN is used.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-23 7:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 0:16 Advising interactive commands Ag Ibragimov
2024-07-23 7:52 ` Andreas Schwab
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).