Is it possible to use advice to not only run your function first, but also prevent the advised function from running at all?
For example, say a command ordinarily calls
read-from-minibuffer to get a return value:
(defun get-name () (read-from-minibuffer "Enter your name: "))
Let's say, in this example, my name never canges. Entering it manually is time-consuming. Can I use the advice system to intercept the call to read-from-minibuffer and return my own value?
For example, something like:
(defun return-my-name (&rest args) "Jack") (defun quick-get-name () ;; Add the intercepting advice, call the function, then remove the advice. (advice-add 'read-from-minibuffer :intercept 'return-my-name) (get-name) (advice-remove 'read-from-minibuffer 'return-my-name))
The key behaviour I need is to be able to fall back on the original function depending on the input. For example, I might want to intercept the command if the prompt is asking for a name, but not if it is asking for some other information, like age:
(defun return-my-name (prompt &rest args) (if (eq prompt "Enter your name: ") "Jack" (read-from-minibuffer prompt))
Anyone know if the advice system is capable of this? Can it be done some other way, for example using aliases?