aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-06-13 16:17:40 +0200
committerLars Ingebrigtsen2022-06-13 16:17:40 +0200
commit57cd069f73808f862c326bac4191ab507f3c973f (patch)
tree0ea1e7f044facb40caca6ea95981a9252d791fe5
parent288ffb25edbf38998aba65182e94b54cb2a3c04f (diff)
downloademacs-57cd069f73808f862c326bac4191ab507f3c973f.tar.gz
emacs-57cd069f73808f862c326bac4191ab507f3c973f.zip
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).
-rw-r--r--doc/emacs/search.texi8
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/replace.el28
3 files changed, 31 insertions, 9 deletions
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index b123ef83a16..f4e12d29e99 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
1827with @kbd{C-M-c} to proceed to the next occurrence. 1827with @kbd{C-M-c} to proceed to the next occurrence.
1828 1828
1829@item e 1829@item e
1830@itemx E
1831to edit the replacement string in the minibuffer. When you exit the 1830to edit the replacement string in the minibuffer. When you exit the
1832minibuffer by typing @key{RET}, the minibuffer contents replace the 1831minibuffer by typing @key{RET}, the minibuffer contents replace the
1833current occurrence of the pattern. They also become the new 1832current occurrence of the pattern. They also become the new
1834replacement string for any further occurrences. 1833replacement string for any further occurrences.
1835 1834
1835@item E
1836is like @kbd{e}, but the next replacement will be done with exact
1837case. I.e., if you have a @code{query-replace} from @samp{foo} to
1838@samp{bar}, a text like @samp{Foo} will be normally be replaced with
1839@samp{Bar}. Use this command to do the current replacement with exact
1840case.
1841
1836@item C-l 1842@item C-l
1837to redisplay the screen. Then you must type another character to 1843to redisplay the screen. Then you must type another character to
1838specify what to do with this occurrence. 1844specify what to do with this occurrence.
diff --git a/etc/NEWS b/etc/NEWS
index 8e3228864c0..1b8560a9239 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -151,6 +151,10 @@ of 'user-emacs-directory'.
151 151
152* Incompatible changes in Emacs 29.1 152* Incompatible changes in Emacs 29.1
153 153
154+++
155** 'E' in 'query-replace' now edits the replacement with exact case.
156Previously, this command did the same as 'e'.
157
154--- 158---
155** '/ a' in *Packages* now limits by package name(s) instead of regexp. 159** '/ a' in *Packages* now limits by package name(s) instead of regexp.
156 160
diff --git a/lisp/replace.el b/lisp/replace.el
index b84e6eaa655..c9d41d3fa39 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2506,7 +2506,8 @@ To be added to `context-menu-functions'."
2506\\`^' to move point back to previous match, 2506\\`^' to move point back to previous match,
2507\\`u' to undo previous replacement, 2507\\`u' to undo previous replacement,
2508\\`U' to undo all replacements, 2508\\`U' to undo all replacements,
2509\\`E' to edit the replacement string. 2509\\`e' to edit the replacement string.
2510\\`E' to edit the replacement string with exact case.
2510In multi-buffer replacements type \\`Y' to replace all remaining 2511In multi-buffer replacements type \\`Y' to replace all remaining
2511matches in all remaining buffers with no more questions, 2512matches in all remaining buffers with no more questions,
2512\\`N' to skip to the next buffer without replacing remaining matches 2513\\`N' to skip to the next buffer without replacing remaining matches
@@ -2524,7 +2525,7 @@ in the current buffer."
2524 (define-key map "Y" 'act) 2525 (define-key map "Y" 'act)
2525 (define-key map "N" 'skip) 2526 (define-key map "N" 'skip)
2526 (define-key map "e" 'edit-replacement) 2527 (define-key map "e" 'edit-replacement)
2527 (define-key map "E" 'edit-replacement) 2528 (define-key map "E" 'edit-replacement-exact-case)
2528 (define-key map "," 'act-and-show) 2529 (define-key map "," 'act-and-show)
2529 (define-key map "q" 'exit) 2530 (define-key map "q" 'exit)
2530 (define-key map "\r" 'exit) 2531 (define-key map "\r" 'exit)
@@ -2561,8 +2562,9 @@ The \"bindings\" in this map are not commands; they are answers.
2561The valid answers include `act', `skip', `act-and-show', 2562The valid answers include `act', `skip', `act-and-show',
2562`act-and-exit', `exit', `exit-prefix', `recenter', `scroll-up', 2563`act-and-exit', `exit', `exit-prefix', `recenter', `scroll-up',
2563`scroll-down', `scroll-other-window', `scroll-other-window-down', 2564`scroll-down', `scroll-other-window', `scroll-other-window-down',
2564`edit', `edit-replacement', `delete-and-edit', `automatic', 2565`edit', `edit-replacement', `edit-replacement-exact-case',
2565`backup', `undo', `undo-all', `quit', and `help'. 2566`delete-and-edit', `automatic', `backup', `undo', `undo-all',
2567`quit', and `help'.
2566 2568
2567This keymap is used by `y-or-n-p' as well as `query-replace'.") 2569This keymap is used by `y-or-n-p' as well as `query-replace'.")
2568 2570
@@ -3336,19 +3338,29 @@ characters."
3336 (setq match-again (and (looking-at search-string) 3338 (setq match-again (and (looking-at search-string)
3337 (match-data))))) 3339 (match-data)))))
3338 ;; Edit replacement. 3340 ;; Edit replacement.
3339 ((eq def 'edit-replacement) 3341 ((or (eq def 'edit-replacement)
3342 (eq def 'edit-replacement-exact-case))
3340 (setq real-match-data (replace-match-data 3343 (setq real-match-data (replace-match-data
3341 nil real-match-data 3344 nil real-match-data
3342 real-match-data) 3345 real-match-data)
3343 next-replacement 3346 next-replacement
3344 (read-string "Edit replacement string: " 3347 (read-string
3345 next-replacement) 3348 (format "Edit replacement string%s: "
3349 (if (eq def
3350 'edit-replacement-exact-case)
3351 " (exact case)"
3352 ""))
3353 next-replacement)
3346 noedit nil) 3354 noedit nil)
3347 (if replaced 3355 (if replaced
3348 (set-match-data real-match-data) 3356 (set-match-data real-match-data)
3349 (setq noedit 3357 (setq noedit
3350 (replace-match-maybe-edit 3358 (replace-match-maybe-edit
3351 next-replacement nocasify literal noedit 3359 next-replacement
3360 (if (eq def 'edit-replacement-exact-case)
3361 t
3362 nocasify)
3363 literal noedit
3352 real-match-data backward) 3364 real-match-data backward)
3353 replaced t) 3365 replaced t)
3354 (setq next-replacement-replaced next-replacement)) 3366 (setq next-replacement-replaced next-replacement))