emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/el-search 9f4a9e5 310/332: [el-search] Improve "Make re


From: Stefan Monnier
Subject: [elpa] externals/el-search 9f4a9e5 310/332: [el-search] Improve "Make replacement editable and ediff'able"
Date: Tue, 1 Dec 2020 15:49:11 -0500 (EST)

branch: externals/el-search
commit 9f4a9e5f691203ea14795e2589cde5898796c0f0
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>

    [el-search] Improve "Make replacement editable and ediff'able"
    
    * packages/el-search/el-search.el
    (el-search-query-replace--comments-preserved-p): Be more accurate when
    skipping the header to extract the edited replacement.
---
 el-search.el | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/el-search.el b/el-search.el
index f8751d8..1c26b49 100644
--- a/el-search.el
+++ b/el-search.el
@@ -4363,13 +4363,8 @@ exactly you did?  Thanks!"))))
                               (edit-replacement
                                (lambda (&optional ediff-only)
                                  (save-excursion ;user may copy stuff from 
base buffer etc.
-                                   (let* ((buffer (generate-new-buffer 
"*Replacement*"))
-                                          (window (display-buffer buffer)))
-                                     (select-window window)
-                                     (emacs-lisp-mode)
-                                     (unless ediff-only
-                                       (insert
-                                        (propertize "\
+                                   (let* ((header
+                                           (propertize "\
 ;; This buffer shows the individual replacement for the current match.
 ;; You may edit it here while query-replace is interrupted by a
 ;; `recursive-edit'.
@@ -4377,9 +4372,21 @@ exactly you did?  Thanks!"))))
 ;; to confirm.
 ;; Type C-c C-e to Ediff the current match with this buffer's content.
 ;; Type C-c C-r to revert this buffer."
-                                                    'read-only t 'field t
-                                                    'front-sticky t 
'rear-nonsticky t)
-                                        "\n\n"))
+                                                       'read-only t 'field t
+                                                       'front-sticky t 
'rear-nonsticky t))
+                                          (find-replacement-beg
+                                           (lambda ()
+                                             (goto-char (point-min))
+                                             (when (looking-at (regexp-quote 
header))
+                                               (goto-char (match-end 0)))
+                                             (while (and (not (eobp)) 
(looking-at "^$"))
+                                               (forward-line))))
+                                          (buffer (generate-new-buffer 
"*Replacement*"))
+                                          (window (display-buffer buffer)))
+                                     (select-window window)
+                                     (emacs-lisp-mode)
+                                     (unless ediff-only
+                                       (insert header "\n\n"))
                                      (save-excursion (insert to-insert))
                                      (let ((inhibit-message t))
                                        (indent-region (point) (point-max)))
@@ -4417,10 +4424,7 @@ exactly you did?  Thanks!"))))
                                           (define-key map [(control ?c) 
(control ?r)]
                                             (lambda ()
                                               (interactive)
-                                              (goto-char (point-min))
-                                              (while (and (not (eobp))
-                                                          (looking-at 
"^;;\\|^$"))
-                                                (forward-line))
+                                              (funcall find-replacement-beg)
                                               (delete-region (point) 
(point-max))
                                               (insert (funcall 
get-replacement-string))))
                                           map))
@@ -4435,11 +4439,9 @@ exactly you did?  Thanks!"))))
                                      (let ((new-to-insert
                                             (and (buffer-modified-p buffer)
                                                  (with-current-buffer buffer
-                                                   (goto-char (point-min))
-                                                   (while (and (not (eobp))
-                                                               (looking-at 
"^;;\\|^$"))
-                                                     (forward-line))
-                                                   (buffer-substring (point) 
(point-max))))))
+                                                   (funcall 
find-replacement-beg)
+                                                   (string-trim
+                                                    (buffer-substring (point) 
(point-max)))))))
                                        (when (and new-to-insert
                                                   (y-or-n-p "Use modified 
version?"))
                                          (setq to-insert new-to-insert)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]