From: Juri Linkov <juri@linkov.net>
To: chris@chrispoole.com
Cc: 20430@debbugs.gnu.org
Subject: bug#20430: 24.5; Enhancement request: extra hook for query-replace and friends
Date: Wed, 03 Jun 2015 01:50:34 +0300 [thread overview]
Message-ID: <87k2vlrah1.fsf@mail.linkov.net> (raw)
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")
> 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)))
next prev parent reply other threads:[~2015-06-02 22:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-26 9:02 bug#20430: 24.5; Enhancement request: extra hook for query-replace and friends Chris, Poole <chris
2015-06-02 22:50 ` Juri Linkov [this message]
2015-12-24 0:41 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k2vlrah1.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=20430@debbugs.gnu.org \
--cc=chris@chrispoole.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).