From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Juri Linkov <juri@linkov.net>
Newsgroups: gmane.emacs.bugs
Subject: bug#20430: 24.5;
	Enhancement request: extra hook for query-replace and friends
Date: Wed, 03 Jun 2015 01:50:34 +0300
Organization: LINKOV.NET
Message-ID: <87k2vlrah1.fsf@mail.linkov.net>
References: <m2383nclec.fsf@Chris-MacBook-Pro.local.i-did-not-set--mail-host-address--so-tickle-me>
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: ger.gmane.org 1433285781 16442 80.91.229.3 (2 Jun 2015 22:56:21 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 2 Jun 2015 22:56:21 +0000 (UTC)
Cc: 20430@debbugs.gnu.org
To: chris@chrispoole.com
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 03 00:56:10 2015
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1Yzv4V-00077S-LL
	for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Jun 2015 00:54:11 +0200
Original-Received: from localhost ([::1]:32938 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1Yzv4V-0005PZ-3x
	for geb-bug-gnu-emacs@m.gmane.org; Tue, 02 Jun 2015 18:54:11 -0400
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40886)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yzv4R-0005PJ-7H
	for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 18:54:08 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yzv4M-0003kK-7i
	for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 18:54:07 -0400
Original-Received: from debbugs.gnu.org ([140.186.70.43]:56305)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yzv4M-0003kG-4c
	for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 18:54:02 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yzv4L-0000me-VN
	for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 18:54:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Juri Linkov <juri@linkov.net>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Tue, 02 Jun 2015 22:54:01 +0000
Resent-Message-ID: <handler.20430.B20430.14332855842884@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20430
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
Original-Received: via spool by 20430-submit@debbugs.gnu.org id=B20430.14332855842884
	(code B ref 20430); Tue, 02 Jun 2015 22:54:01 +0000
Original-Received: (at 20430) by debbugs.gnu.org; 2 Jun 2015 22:53:04 +0000
Original-Received: from localhost ([127.0.0.1]:38047 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1Yzv3P-0000kR-BO
	for submit@debbugs.gnu.org; Tue, 02 Jun 2015 18:53:03 -0400
Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:55588
	helo=homiemail-a18.g.dreamhost.com)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <juri@linkov.net>) id 1Yzv3N-0000k0-3A
	for 20430@debbugs.gnu.org; Tue, 02 Jun 2015 18:53:01 -0400
Original-Received: from homiemail-a18.g.dreamhost.com (localhost [127.0.0.1])
	by homiemail-a18.g.dreamhost.com (Postfix) with ESMTP id 41C9425006C;
	Tue,  2 Jun 2015 15:53:00 -0700 (PDT)
Original-Received: from localhost.linkov.net (m83-176-9-1.cust.tele2.ee [83.176.9.1])
	(Authenticated sender: jurta@jurta.org)
	by homiemail-a18.g.dreamhost.com (Postfix) with ESMTPA id 1993A25006B; 
	Tue,  2 Jun 2015 15:52:58 -0700 (PDT)
In-Reply-To: <m2383nclec.fsf@Chris-MacBook-Pro.local.i-did-not-set--mail-host-address--so-tickle-me>
	(Chris@chris-macbook-pro.local's message of "Sun, 26 Apr 2015 10:02:35
	+0100")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (x86_64-pc-linux-gnu)
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
	the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
	<mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
	<mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.bugs:103524
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/103524>

> 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)))