[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/el-search effcb50 271/332: [el-search] Make r hit twice
From: |
Stefan Monnier |
Subject: |
[elpa] externals/el-search effcb50 271/332: [el-search] Make r hit twice restore a replaced match |
Date: |
Tue, 1 Dec 2020 15:49:01 -0500 (EST) |
branch: externals/el-search
commit effcb50dda9fb5ac97268cc6aa080fe94f4ad5a7
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>
[el-search] Make r hit twice restore a replaced match
Update commentary in header accordingly.
* packages/el-search/el-search.el
(el-search--search-and-replace-pattern): Make r hit after replacing a
match restore that match using an undo change group.
---
el-search.el | 132 +++++++++++++++++++++++++++++++++--------------------------
1 file changed, 74 insertions(+), 58 deletions(-)
diff --git a/el-search.el b/el-search.el
index d598a2b..c2347a3 100644
--- a/el-search.el
+++ b/el-search.el
@@ -298,9 +298,10 @@
;; `(foo ,b ,a . ,rest) RET
;;
;; Type y to replace a match and go to the next one, r to replace
-;; without moving, n to go to the next match without replacing and !
-;; to replace all remaining matches automatically. q quits. ? shows
-;; a quick help summarizing all of these keys.
+;; without moving (hitting r again restores that match), n to go to
+;; the next match without replacing and ! to replace all remaining
+;; matches automatically. q quits. ? shows a quick help summarizing
+;; all of these keys.
;;
;; It is possible to replace a match with an arbitrary number of
;; expressions using "splicing mode". When it is active, the
@@ -3717,8 +3718,10 @@ exactly you did? Thanks!"))))
"Replace match and move to
the next"))
(and (not replaced-this)
'(?n "n" "Move to the next
match"))
- (and (not replaced-this)
- '(?r "r" "Replace match but
don't move"))
+ `(?r "r"
+ ,(if (not replaced-this)
+ "Replace match but don't
move"
+ "Restore match"))
'(?! "all" "Replace all remaining
matches in this buffer")
'(?b "skip buf"
"Skip this buffer and any
remaining matches in it")
@@ -3735,63 +3738,76 @@ Toggle splicing mode (\\[describe-function]
el-search-query-replace for details)
'(?\r "quit"))))))))
(if replace-all
(funcall do-replace)
- (while (not (pcase (funcall query)
- (?r (funcall do-replace)
- nil)
- (?y
- (unless replaced-this (funcall
do-replace))
- t)
- (?n
- (cl-incf nbr-skipped)
- t)
- (?!
- (when (and use-current-search
- (not (alist-get
'is-single-buffer
-
(el-search-object-properties
-
el-search--current-search)))
- (eq (car
(read-multiple-choice
- "Replace in all
following buffers?"
- '((?! "Only
this"
- "\
+ (let ((handle nil))
+ (unwind-protect
+ (while (not (pcase (funcall query)
+ (?r
+ (if (not replaced-this)
+ (progn
+ (activate-change-group
+ (setq handle
(prepare-change-group)))
+ (funcall do-replace))
+ (cancel-change-group handle)
+ (setq handle nil)
+ (setq replaced-this nil)
+ (cl-decf nbr-replaced)
+ (cl-decf nbr-replaced-total))
+ nil)
+ (?y
+ (unless replaced-this (funcall
do-replace))
+ t)
+ (?n
+ (cl-incf nbr-skipped)
+ t)
+ (?!
+ (when (and use-current-search
+ (not (alist-get
'is-single-buffer
+
(el-search-object-properties
+
el-search--current-search)))
+ (eq (car
(read-multiple-choice
+ "Replace
in all following buffers?"
+ '((?!
"Only this"
+ "\
Replace only remaining matches in this buffer")
- (?A "All
buffers"
- "\
+ (?A
"All buffers"
+ "\
Replace all matches in all buffers"))))
- ?A))
- (setq replace-all-and-following t))
- (setq replace-all t)
- (unless replaced-this (funcall
do-replace))
- t)
- (?b (goto-char (point-max))
- (message "Skipping this buffer")
- (sit-for 1)
- ;; FIXME: add #skipped matches to
nbr-skipped?
- t)
- (?d (call-interactively
#'el-search-skip-directory)
- t)
- (?s
- (setq splice (not splice)
- to-insert (funcall
get-replacement-string))
- nil)
- (?o
- ;; FIXME: Should we allow to edit
the replacement?
- (let* ((buffer (get-buffer-create
-
(generate-new-buffer-name "*Replacement*")))
- (window (display-buffer
buffer)))
- (with-selected-window window
- (emacs-lisp-mode)
- (save-excursion
- (insert
- "\
+ ?A))
+ (setq
replace-all-and-following t))
+ (setq replace-all t)
+ (unless replaced-this (funcall
do-replace))
+ t)
+ (?b (goto-char (point-max))
+ (message "Skipping this
buffer")
+ (sit-for 1)
+ ;; FIXME: add #skipped
matches to nbr-skipped?
+ t)
+ (?d (call-interactively
#'el-search-skip-directory)
+ t)
+ (?s
+ (setq splice (not splice)
+ to-insert (funcall
get-replacement-string))
+ nil)
+ (?o
+ ;; FIXME: Should we allow to
edit the replacement?
+ (let* ((buffer
(get-buffer-create
+
(generate-new-buffer-name "*Replacement*")))
+ (window (display-buffer
buffer)))
+ (with-selected-window window
+ (emacs-lisp-mode)
+ (save-excursion
+ (insert
+ "\
;; This buffer shows the replacement for the current match.
;; Please hit any key to proceed.\n\n"
- (funcall
get-replacement-string)))
- (read-char " "))
- (delete-window window)
- (kill-buffer buffer)
- (el-search--after-scroll
(selected-window) (window-start))
- nil))
- ((or ?q ?\C-g ?\r) (signal 'quit
t))))))
+ (funcall
get-replacement-string)))
+ (read-char " "))
+ (delete-window window)
+ (kill-buffer buffer)
+ (el-search--after-scroll
(selected-window) (window-start))
+ nil))
+ ((or ?q ?\C-g ?\r) (signal
'quit t)))))
+ (when handle (accept-change-group handle)))))
(unless (eobp)
(let* ((replacement-end-pos
(and replaced-this
- [elpa] externals/el-search 6c0475e 212/332: Allow to save the current el-search to a register, (continued)
- [elpa] externals/el-search 6c0475e 212/332: Allow to save the current el-search to a register, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 7c19468 215/332: Fix el-search's to register save when no search started yet, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search c7709ab 233/332: Fix el-search's check for buffers visiting a given file, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search cda69ae 230/332: * el-search/el-search-x.el: New user option `el-search-lazy-l', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search ce8835b 242/332: [el-search] Factor out `el-search-backward', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search dfaa7f2 244/332: [el-search] Some more minor tweaks, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search a6c23b5 250/332: * el-search/el-search.el: Correct NOERROR argument uses, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 2a02a81 277/332: [el-search] Let el-search-query-replace add undo boundaries, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 864f0ed 276/332: [el-search] Provide el-search-occur-search-object earlier, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 23cf24d 275/332: [el-search] Enhancements to my last two commits, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search effcb50 271/332: [el-search] Make r hit twice restore a replaced match,
Stefan Monnier <=
- [elpa] externals/el-search b9ba337 283/332: [el-search] Allow to work without installing key bindings, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 841a027 287/332: [el-search] Some optimization tweaks, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 70634b7 298/332: [el-search] Avoid bytecomp warning windows pop up, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 22c2f25 297/332: [el-search] Display colored defun match count, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 061464c 303/332: [el-search] Improvise eldoc support for search pattern prompt, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 9f4a9e5 310/332: [el-search] Improve "Make replacement editable and ediff'able", Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 3da4529 316/332: [el-search] Minor tweaks and version bump, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e96c51e 319/332: [el-search] Key syntax cleanup, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search f091ed5 320/332: [el-search] Prefer rx forms to stringish regexps, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 47ee6b1 226/332: Improve working of `el-search-kill-left-over-search-buffers', Stefan Monnier, 2020/12/01