In the company where I work we use Emacs as the default editor for the LaTeX copy-editing tasks and we share some Emacs scripts to automate/guide some operations.
Actually I need to perform some query-replacements into the LaTeX code and to make my colleagues aware of the purpose of these replacements. To do this I use this kind of functions in my scripts:
(query-replace-with-info "foo"
"bar"
"This replacement is appropriate in the following cases..."
nil (point-min) (point-max))
making Emacs behave like in the following figure:

To build my query-replace-with-info function I hacked the perform-replace function in this way: https://pastebin.com/79y7PKP7
The problem with this is that I cannot easily mantain the code if perform-replace will be updated in newer Emacs versions.
So I'd like to write a macro in this form:
(with-query-replace-description
"This replacement is appropriate in the following cases..."
(query-replace "foo"
"bar"
nil (point-min) (point-max)))
The description could be displayed in a temp-buffer.
Any suggestions?
Info added
I added an extra argument INFO-STRING to the original perform-replace function:
(defun perform-replace-with-info (from-string replacements
query-flag regexp-flag INFO-STRING delimited-flag
&optional repeat-count map start end backward region-noncontiguous-p)
...
and, in the let arguments, I added:
(info-string (if INFO-STRING
(propertize
(concat INFO-STRING "\n\n")
'face '(:foreground "goldenrod"
;; :background "DarkGoldenrod1"
))
;; *ELSE*
""))
Finally I modified the original message argument in the let args, this way:
(message
(if query-flag
(concat ; <-- The magic
info-string ; <--
(apply 'propertize
(substitute-command-keys
"Query replacing %s with %s: (\\<query-replace-map>\\[help] for help) ")
minibuffer-prompt-properties)))))
Can this be done with the advice tecnique suggested by Drew in the comments? (I just read that advice could be evil... please ignore this last question.)


perform-replace, it sounds like you're just wrapping what it does with a function that displays some text. If I'm missing what you're saying, maybe say in your question why Emacs advice wouldn't be appropriate, to give a better idea of what you need/want.perform-replacefunction and I concatenated ((concat)) it to the original message diplayed by the function.messageis a variable declared in theletpart of fheperform-replacefunction.nadvicesystem.)