]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow `query-replace' to do exact replacement of the current item
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 13 Jun 2022 14:17:40 +0000 (16:17 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 13 Jun 2022 14:17:40 +0000 (16:17 +0200)
* 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
etc/NEWS
lisp/replace.el

index b123ef83a1607749c1979c7bc2fc5933e31578c7..f4e12d29e9904df5acf0010a0895c202563a6c70 100644 (file)
@@ -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.
index 8e3228864c0d914db041ac5c039ff0deed0a017c..1b8560a92394895356c8b13936820b7a7cd2ee48 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -151,6 +151,10 @@ of 'user-emacs-directory'.
 \f
 * 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.
 
index b84e6eaa6555520ef6a3f88d350fd502b84b481f..c9d41d3fa39aa4692a5293fa1f19dcc4e21d7be8 100644 (file)
@@ -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))