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

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

[elpa] externals/m-buffer fff98c95e3 030/115: Return type of replace-mat


From: ELPA Syncer
Subject: [elpa] externals/m-buffer fff98c95e3 030/115: Return type of replace-match changed to start end markers. New function `clone-markers'
Date: Tue, 19 Jul 2022 15:58:46 -0400 (EDT)

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

    Return type of replace-match changed to start end markers. New function 
`clone-markers'
    Implementation is also changed so that markers are now shared with 
match-data.
---
 m-buffer.el           | 16 +++++++++++++---
 test/m-buffer-test.el | 24 +++++++++++++++++-------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/m-buffer.el b/m-buffer.el
index 281df4cdd8..40ef413980 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -308,7 +308,13 @@ See also `m-buffer-nil-markers'"
 (defun m-buffer-marker-tree-to-pos-nil (marker-tree)
   (m-buffer-marker-tree-to-pos marker-tree t))
 
-(defun m-buffer-pos-to-markers (buffer positions)
+(defun m-buffer-marker-clone (marker-tree &optional type)
+  (-tree-map
+   (lambda (marker)
+     (copy-marker marker type))
+   marker-tree))
+
+(defun m-buffer-pos-to-marker (buffer positions)
   "In BUFFER translates a list of POSITIONS to markers."
   (-map
    (lambda (pos)
@@ -318,7 +324,9 @@ See also `m-buffer-nil-markers'"
 
 (defun m-buffer-replace-match (match-data replacement &optional subexp)
   "Given a list of MATCH-DATA, replace with REPLACEMENT.
-SUBEXP should be a number indicating the regexp group to replace."
+SUBEXP should be a number indicating the regexp group to replace.
+Returns markers to the start and end of the replacement. These
+markers are part of MATCH-DATA, and will be niled if they are."
   (-map
    (lambda (match)
      (with-current-buffer
@@ -328,7 +336,9 @@ SUBEXP should be a number indicating the regexp group to 
replace."
          (replace-match
           replacement nil nil nil
           (or subexp 0)))))
-   match-data))
+   match-data)
+  ;; we have match-data 
+  (m-buffer-match-nth-group (or subexp 0) match-data))
 
 (defun m-buffer-match-string (match-data &optional subexp)
   "Given a list of MATCH-DATA return the string matches optionally
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 1397203c4b..4645afe6cf 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -112,10 +112,10 @@
       "^one$")))))
 
 
-(ert-deftest markers-to-pos ()
+(ert-deftest marker-to-pos ()
   (should
    (equal '(1 1 1)
-          (m-buffer-markers-to-pos-nil
+          (m-buffer-marker-to-pos-nil
            (list
             (copy-marker 1)
             (copy-marker 1)
@@ -131,7 +131,7 @@
       (current-buffer)
       "^one$")))))
 
-(ert-deftest m-buffer-nil-markers ()
+(ert-deftest m-buffer-nil-marker ()
   (should
    (m-buffer-wtb-of-file
     "match-data.txt"
@@ -149,11 +149,21 @@
        (and
         (not (marker-position marker))
         (not (marker-buffer marker))))
-     (m-buffer-nil-markers
+     (m-buffer-nil-marker
       (m-buffer-match-begin (current-buffer) "^one$"))))))
 
 
 (ert-deftest replace-matches ()
+  (should
+   (equal
+    '((1 6) (11 16) (21 26))
+    (m-buffer-wtb-of-file
+     "match-data.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-replace-match
+       (m-buffer-match-data
+        (current-buffer) "^one$") "three")))))
+
   (should
    (equal
     "three\ntwo\nthree\ntwo\nthree\ntwo\n"
@@ -181,7 +191,7 @@
     '(1 2 3 5 7 10 13)
     (m-buffer-wtb-of-file
      "line-start.txt"
-     (m-buffer-markers-to-pos
+     (m-buffer-marker-to-pos
       (m-buffer-match-line-start (current-buffer)))))))
 
 (ert-deftest line-end ()
@@ -190,7 +200,7 @@
     '(1 2 4 6 9 12 13)
     (m-buffer-wtb-of-file
        "line-start.txt"
-       (m-buffer-markers-to-pos
+       (m-buffer-marker-to-pos
         (m-buffer-match-line-end (current-buffer)))))))
 
 (ert-deftest sentence-end ()
@@ -199,7 +209,7 @@
     '(15 32 48)
     (m-buffer-wtb-of-file
      "sentence-end.txt"
-     (m-buffer-markers-to-pos
+     (m-buffer-marker-to-pos
       (m-buffer-match-sentence-end (current-buffer)))))))
 
 (ert-deftest buffer-for-match ()



reply via email to

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