[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Advising interactive commands
From: |
Ag Ibragimov |
Subject: |
Advising interactive commands |
Date: |
Mon, 22 Jul 2024 19:16:41 -0500 |
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?
- Advising interactive commands,
Ag Ibragimov <=