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

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

[elpa] externals/m-buffer 643fbef4bf 078/115: replace-match now saves po


From: ELPA Syncer
Subject: [elpa] externals/m-buffer 643fbef4bf 078/115: replace-match now saves point
Date: Tue, 19 Jul 2022 15:58:50 -0400 (EDT)

branch: externals/m-buffer
commit 643fbef4bf0d8aa5a2b0c1c9b1c887241aa095da
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    replace-match now saves point
    
    Previously, the replace-match functions moved point. This has now been
    fixed.
---
 Makefile              |  2 +-
 m-buffer.el           | 22 ++++++++++++----------
 test/m-buffer-test.el | 17 +++++++++++++++++
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index d78ddf2820..50524b2d5b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ all: install test
 install:
        cask install
 
-test:
+test: install
        cask exec ert-runner
 
 
diff --git a/m-buffer.el b/m-buffer.el
index 637f736118..ecf884cf98 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -538,19 +538,21 @@ Returns markers to the start and end of the replacement. 
These
 markers are part of MATCH-DATA, so niling them will percolate backward.
 
 See also `replace-match'."
-  (-map
-   (lambda (match)
-     (with-current-buffer
-         (marker-buffer (car match))
-       (save-match-data
-         (set-match-data match)
-         (replace-match
-          replacement fixedcase literal nil
-          (or subexp 0)))))
-   match-data)
+  (save-excursion
+    (-map
+     (lambda (match)
+       (with-current-buffer
+           (marker-buffer (car match))
+         (save-match-data
+           (set-match-data match)
+           (replace-match
+            replacement fixedcase literal nil
+            (or subexp 0)))))
+     match-data))
   ;; we have match-data
   (m-buffer-match-nth-group (or subexp 0) match-data))
 
+
 (defun m-buffer-delete-match (match-data &optional subexp)
   "Delete all MATCH-DATA.
 SUBEXP should be a number indicating the regexp group to delete.
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index a0e9ae3eea..fcb3d66960 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -384,4 +384,21 @@
        (19 31 19 19))
      '((1 18))))))
 
+
+(ert-deftest replace-point-unmoved ()
+  "After a replace-match has happened point
+should not have moved."
+  (should
+   (equal
+    (m-buffer-wtb-of-file
+     "match-data.txt"
+     (point-min))
+    (m-buffer-wtb-of-file
+     "match-data.txt"
+     (m-buffer-replace-match
+      (m-buffer-match
+       (current-buffer) "two")
+      "one")
+     (point)))))
+
 ;;; m-buffer-test.el ends here



reply via email to

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