Define an emacs command that invokes another emacs command (keeping interactive content)
How can I define an emacs X command that does something and then invokes another emacs Y command and also copies the interactive interface of the Y command?
I want to define an alternative version of query-replace with modified case-fold-search time value:
(defun alt-query-replace (a b c d e)
(interactive)
(let ((case-fold-search (not case-fold-search))
(query-replace a b c d e)))
This does not work. When I call alt-query-replace it says "wrong number of arguments". I want the interactive alt-query-replace interface to be the same as query-replace. Do I need to validate the source code of the replacement request or is there a general approach?
source to share
You can advise the original function if you want to change its behavior instead of calling a separate function.
From chapter 17.3 Around- tip of the GNU Emacs Lisp reference manual:
Around-advice lets you wrap a Lisp expression around the original function definition.
(defadvice foo (around foo-around) "Ignore case in `foo'." (let ((case-fold-search t)) ad-do-it))
In your case, you can write:
(defadvice query-replace (around alt-query-replace (from-string to-string &optional delimited start end))
(let ((case-fold-search (not case-fold-search)))
ad-do-it))
(ad-activate 'query-replace)
source to share