branch: externals/m-buffer
commit e4ec4daa8743bf05bd8aee5fbd8eef9cd55546a4
Author: Phillip Lord <[email protected]>
Commit: Phillip Lord <[email protected]>
replace-match now returns marker to the end of the replacements.
---
m-buffer.el | 6 ++++--
test/m-buffer-test.el | 10 ++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/m-buffer.el b/m-buffer.el
index 9b22bc4a68..d5a687f802 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -318,7 +318,8 @@ 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 a list of markers to the end of the replacement."
(-map
(lambda (match)
(with-current-buffer
@@ -327,7 +328,8 @@ SUBEXP should be a number indicating the regexp group to
replace."
(set-match-data match)
(replace-match
replacement nil nil nil
- (or subexp 0)))))
+ (or subexp 0))
+ (point-marker))))
match-data))
(defun m-buffer-match-string (match-data &optional subexp)
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index df4e7661b7..92b34e8d08 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -154,6 +154,16 @@
(ert-deftest replace-matches ()
+ (should
+ (equal
+ '(6 16 26)
+ (m-buffer-wtb-of-file
+ "match-data.txt"
+ (m-buffer-marker-to-pos
+ (m-buffer-replace-match
+ (m-buffer-match-data
+ (current-buffer) "^one$") "three")))))
+
(should
(equal
"three\ntwo\nthree\ntwo\nthree\ntwo\n"