bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20430: 24.5; Enhancement request: extra hook for query-replace and f


From: Juri Linkov
Subject: bug#20430: 24.5; Enhancement request: extra hook for query-replace and friends
Date: Wed, 03 Jun 2015 01:50:34 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (x86_64-pc-linux-gnu)

> Would be very useful to have a hook that's called when the next
> potential match item is shown with isearch, query-replace, etc.
>
> Hook should run after point is moved to the next search hit and before
> reading your input char.
>
> Explanation and justification comes from answer to my question:
> http://emacs.stackexchange.com/a/10903/7132

It's possible to recenter in query-replace by adding an advice
on isearch-search-fun-default like it was possible to recenter
in isearch by advising isearch-update.  To make it simpler,
a special hook `isearch-update-post-hook' was already added, so
a similar hook `replace-update-post-hook' could be added for
query-replace as well:

diff --git a/lisp/replace.el b/lisp/replace.el
index 1bf1343..fc47dda 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1978,6 +1978,9 @@ passed in.  If LITERAL is set, no checking is done, 
anyway."
   (when backward (goto-char (nth 0 match-data)))
   noedit)
 
+(defvar replace-update-post-hook nil
+  "Function(s) to call after query-replace has found matches in the buffer.")
+
 (defvar replace-search-function nil
   "Function to use when searching for strings to replace.
 It is used by `query-replace' and `replace-string', and is called
@@ -2274,6 +2276,7 @@ make, or the user didn't cancel the call."
                               (match-substitute-replacement next-replacement
                                                             nocasify literal))
                           next-replacement)))
+                    (run-hooks 'replace-update-post-hook)
                    (message message
                              (query-replace-descr from-string)
                              (query-replace-descr replacement-presentation)))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]