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

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

[elpa] externals/m-buffer 5c46bf8102 017/115: Added function m-buffer-on


From: ELPA Syncer
Subject: [elpa] externals/m-buffer 5c46bf8102 017/115: Added function m-buffer-on-region -- apply a function to a region.
Date: Tue, 19 Jul 2022 15:58:45 -0400 (EDT)

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

    Added function m-buffer-on-region -- apply a function to a region.
---
 m-buffer.el           | 24 ++++++++++++++++++++++++
 test/m-buffer-test.el | 13 +++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/m-buffer.el b/m-buffer.el
index 831d6e6b95..3ec9de5641 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -451,5 +451,29 @@ succeeds."
     (error 'end-of-buffer
            nil)))
 
+;;
+;; Apply function to things
+;;
+(defun m-buffer-on-region (fn match-data)
+  "Apply FN to MATCH-DATA.
+FN should take two args, the start and stop of each region.
+MATCH-DATA can be any list of lists with two elements (or more)."
+  (m-buffer-on-region-nth-group fn 0 match-data))
+
+(defun m-buffer-on-region-nth-group (fn n match-data)
+  "Apply FN to the Nth group of MATCH-DATA.
+FN should take two args, the start and stop of each region.
+MATCH-DATA can be any list of lists with two elements (or more)."
+  (-map
+   (lambda (x)
+     (apply fn x))
+   (m-buffer-match-nth-group n match-data)))
+
+;;
+;; Highlight things
+;;
+
+
+
 (provide 'm-buffer)
 ;;; m-buffer.el ends here
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index e16cef1a8f..a6ede5da68 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -236,6 +236,15 @@
           "\\(one\\)\\(two\\)")))))))
 
 
-
-
+(ert-deftest apply-functions ()
+  (should
+   (equal
+    '("onetwo" "onetwo" "onetwo" "onetwo" "")
+    (m-buffer-wtb-of-file
+     "nth.txt"
+     (m-buffer-on-region
+      (lambda (from to)
+        (buffer-substring-no-properties from to))
+      (m-buffer-match-line
+       (current-buffer)))))))
 ;;; m-buffer-test.el ends here



reply via email to

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