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

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

[elpa] externals/m-buffer 1cc4d8cffb 015/115: Added functions: m-buffer-


From: ELPA Syncer
Subject: [elpa] externals/m-buffer 1cc4d8cffb 015/115: Added functions: m-buffer-marker-tree-to-pos, m-buffer-match-nth-group.
Date: Tue, 19 Jul 2022 15:58:45 -0400 (EDT)

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

    Added functions: m-buffer-marker-tree-to-pos, m-buffer-match-nth-group.
---
 m-buffer.el           | 24 ++++++++++++++++++++++++
 test/m-buffer-test.el | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/m-buffer.el b/m-buffer.el
index 0316366f0c..831d6e6b95 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -178,6 +178,16 @@ args, assume they are of the form accepted by
    (t
     (error "Invalid arguments"))))
 
+(defun m-buffer-match-nth-group (n match-data)
+  "From MATCH-DATA, fetch the match to the nth match group."
+  (-map
+   (lambda (m)
+     (let ((drp
+            (-drop (* 2 n) m)))
+       (list
+        (car drp) (cadr drp))))
+   match-data))
+
 (defun m-buffer-match-begin-n (n &rest match)
   "Return markers to the start of the match to the nth group.
 MATCH may be of any form accepted by `m-buffer-ensure-match'. Use
@@ -277,6 +287,20 @@ movement. Or use `m-buffer-markers-to-pos-nil'."
 See also `m-buffer-nil-markers'"
   (m-buffer-markers-to-pos markers t))
 
+(defun m-buffer-marker-tree-to-pos (marker-tree &optional postnil)
+  (-tree-map
+   (lambda (marker)
+     (prog1
+         (marker-position marker)
+       (when postnil
+         (set-marker marker nil))))
+   marker-tree))
+
+(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)
   "In BUFFER translates a list of POSITIONS to markers."
   (-map
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index bb8ce5d03c..e16cef1a8f 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -202,5 +202,40 @@
      (m-buffer-markers-to-pos
       (m-buffer-match-sentence-end (current-buffer)))))))
 
+(ert-deftest match-n ()
+  (should
+   (equal
+    '((1 7 1 4 4 7) (8 14 8 11 11 14) (15 21 15 18 18 21) (22 28 22 25 25 28))
+    (m-buffer-wtb-of-file
+     "nth.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match-data
+       (current-buffer)
+       "\\(one\\)\\(two\\)")))))
+
+  (should
+   (equal
+    '((1 7)(8 14)(15 21)(22 28))
+    (m-buffer-wtb-of-file
+     "nth.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match-nth-group
+       0 (m-buffer-match-data
+          (current-buffer)
+          "\\(one\\)\\(two\\)"))))))
+
+  (should
+   (equal
+    '((1 4) (8 11) (15 18) (22 25))
+    (m-buffer-wtb-of-file
+     "nth.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match-nth-group
+       1 (m-buffer-match-data
+          (current-buffer)
+          "\\(one\\)\\(two\\)")))))))
+
+
+
 
 ;;; m-buffer-test.el ends here



reply via email to

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