[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 57cd069f73: Allow `query-replace' to do exact replacement of the
From: |
Lars Ingebrigtsen |
Subject: |
master 57cd069f73: Allow `query-replace' to do exact replacement of the current item |
Date: |
Mon, 13 Jun 2022 10:17:54 -0400 (EDT) |
branch: master
commit 57cd069f73808f862c326bac4191ab507f3c973f
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow `query-replace' to do exact replacement of the current item
* doc/emacs/search.texi (Query Replace): Document it.
* lisp/replace.el (query-replace-help): Amend help text.
(query-replace-map): Bind `E' to the exact case replacement.
(perform-replace): Allow editing a replacement with exact case
(bug#8504).
---
doc/emacs/search.texi | 8 +++++++-
etc/NEWS | 4 ++++
lisp/replace.el | 28 ++++++++++++++++++++--------
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index b123ef83a1..f4e12d29e9 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -1827,12 +1827,18 @@ occurrence of @var{string}. When done, exit the
recursive editing level
with @kbd{C-M-c} to proceed to the next occurrence.
@item e
-@itemx E
to edit the replacement string in the minibuffer. When you exit the
minibuffer by typing @key{RET}, the minibuffer contents replace the
current occurrence of the pattern. They also become the new
replacement string for any further occurrences.
+@item E
+is like @kbd{e}, but the next replacement will be done with exact
+case. I.e., if you have a @code{query-replace} from @samp{foo} to
+@samp{bar}, a text like @samp{Foo} will be normally be replaced with
+@samp{Bar}. Use this command to do the current replacement with exact
+case.
+
@item C-l
to redisplay the screen. Then you must type another character to
specify what to do with this occurrence.
diff --git a/etc/NEWS b/etc/NEWS
index 8e3228864c..1b8560a923 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -151,6 +151,10 @@ of 'user-emacs-directory'.
* Incompatible changes in Emacs 29.1
++++
+** 'E' in 'query-replace' now edits the replacement with exact case.
+Previously, this command did the same as 'e'.
+
---
** '/ a' in *Packages* now limits by package name(s) instead of regexp.
diff --git a/lisp/replace.el b/lisp/replace.el
index b84e6eaa65..c9d41d3fa3 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2506,7 +2506,8 @@ To be added to `context-menu-functions'."
\\`^' to move point back to previous match,
\\`u' to undo previous replacement,
\\`U' to undo all replacements,
-\\`E' to edit the replacement string.
+\\`e' to edit the replacement string.
+\\`E' to edit the replacement string with exact case.
In multi-buffer replacements type \\`Y' to replace all remaining
matches in all remaining buffers with no more questions,
\\`N' to skip to the next buffer without replacing remaining matches
@@ -2524,7 +2525,7 @@ in the current buffer."
(define-key map "Y" 'act)
(define-key map "N" 'skip)
(define-key map "e" 'edit-replacement)
- (define-key map "E" 'edit-replacement)
+ (define-key map "E" 'edit-replacement-exact-case)
(define-key map "," 'act-and-show)
(define-key map "q" 'exit)
(define-key map "\r" 'exit)
@@ -2561,8 +2562,9 @@ The \"bindings\" in this map are not commands; they are
answers.
The valid answers include `act', `skip', `act-and-show',
`act-and-exit', `exit', `exit-prefix', `recenter', `scroll-up',
`scroll-down', `scroll-other-window', `scroll-other-window-down',
-`edit', `edit-replacement', `delete-and-edit', `automatic',
-`backup', `undo', `undo-all', `quit', and `help'.
+`edit', `edit-replacement', `edit-replacement-exact-case',
+`delete-and-edit', `automatic', `backup', `undo', `undo-all',
+`quit', and `help'.
This keymap is used by `y-or-n-p' as well as `query-replace'.")
@@ -3336,19 +3338,29 @@ characters."
(setq match-again (and (looking-at search-string)
(match-data)))))
;; Edit replacement.
- ((eq def 'edit-replacement)
+ ((or (eq def 'edit-replacement)
+ (eq def 'edit-replacement-exact-case))
(setq real-match-data (replace-match-data
nil real-match-data
real-match-data)
next-replacement
- (read-string "Edit replacement string: "
- next-replacement)
+ (read-string
+ (format "Edit replacement string%s: "
+ (if (eq def
+ 'edit-replacement-exact-case)
+ " (exact case)"
+ ""))
+ next-replacement)
noedit nil)
(if replaced
(set-match-data real-match-data)
(setq noedit
(replace-match-maybe-edit
- next-replacement nocasify literal noedit
+ next-replacement
+ (if (eq def 'edit-replacement-exact-case)
+ t
+ nocasify)
+ literal noedit
real-match-data backward)
replaced t)
(setq next-replacement-replaced next-replacement))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 57cd069f73: Allow `query-replace' to do exact replacement of the current item,
Lars Ingebrigtsen <=