[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/m-buffer 761ba8e4b7 049/115: Equals and subtract functi
From: |
ELPA Syncer |
Subject: |
[elpa] externals/m-buffer 761ba8e4b7 049/115: Equals and subtract functionality added. |
Date: |
Tue, 19 Jul 2022 15:58:48 -0400 (EDT) |
branch: externals/m-buffer
commit 761ba8e4b7c770647d23a91871365e7bc6d9305b
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>
Equals and subtract functionality added.
---
m-buffer.el | 40 ++++++++++++++++++++++++++++++++++++++++
test/m-buffer-test.el | 30 +++++++++++++++++++++++++++++-
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/m-buffer.el b/m-buffer.el
index 185e35f981..7ca2dafab6 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -297,6 +297,46 @@ function. See `m-buffer-nil-marker' for details."
(m-buffer-marker-to-pos-nil
(apply 'm-buffer-match-end match)))
+(defun m-buffer-match-equal (m n)
+ "Returns true if m and n are cover the same region.
+Matches are equal if they match the same region; subgroups are
+ignored."
+ ;; can we speed this up by not making subsets?
+ (equal
+ (-take 2 m)
+ (-take 2 n)))
+
+(defun m-buffer-match-subtract (m n)
+ "Remove from M any matches in N.
+Matches are equivalent if overall they match the same
+area; subgroups are ignored.
+See also `m-buffer-match-exact-subtract' which often
+runs faster but has some restrictions."
+ (-remove
+ (lambda (o)
+ (-any?
+ (lambda (p)
+ (m-buffer-match-equal o p))
+ n))
+ m))
+
+(defun m-buffer-match-exact-subtract (m n)
+ "Remove from M any matches in N.
+Both M and N must be fully ordered, and any element in N must be
+in M."
+ ;; copy n
+ (let ((n-eaten n))
+ (-remove
+ (lambda (o)
+ ;; check the first element of n
+ (when (m-buffer-match-equal
+ (car n-eaten) o)
+ ;; we have a match so throw away the first element of n-eaten
+ ;; which we won't need again.
+ (setq n-eaten (-drop 1 n-eaten))
+ t))
+ m)))
+
;; marker/position utility functions
(defun m-buffer-nil-marker (markers)
"Takes a (nested) list of markers and nils them all.
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 63ec642c8e..0dd7b5aa86 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -157,7 +157,6 @@
(m-buffer-nil-marker
(m-buffer-match-begin (current-buffer) "^one$"))))))
-
(ert-deftest replace-matches ()
(should
(equal
@@ -307,4 +306,33 @@
(current-buffer)
"A"
:case-fold-search t))))))
+
+
+(ert-deftest subtract ()
+ (should
+ (equal
+ '((1 6) (17 23) (34 39))
+ (m-buffer-wtb-of-file
+ "sentence-end.txt"
+ (m-buffer-marker-tree-to-pos
+ (m-buffer-match-subtract
+ (m-buffer-match-word
+ (current-buffer))
+ (m-buffer-match
+ (current-buffer) "sentence")))))))
+
+(ert-deftest exact-substract ()
+ (should
+ (equal
+ '((1 6) (17 23) (34 39))
+ (m-buffer-wtb-of-file
+ "sentence-end.txt"
+ (m-buffer-marker-tree-to-pos
+ (m-buffer-match-exact-subtract
+ (m-buffer-match-word
+ (current-buffer))
+ (m-buffer-match
+ (current-buffer) "sentence")))))))
+
+
;;; m-buffer-test.el ends here
- [elpa] externals/m-buffer 650235fbdb 011/115: Build URL update., (continued)
- [elpa] externals/m-buffer 650235fbdb 011/115: Build URL update., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 22d6b0d640 012/115: Beginning has become begin. Widen option added. New line matching functions., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer c65b7b20c0 014/115: match-data-1 was failing on final match due to off-by-one error., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 1cc4d8cffb 015/115: Added functions: m-buffer-marker-tree-to-pos, m-buffer-match-nth-group., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 27380daef5 018/115: Functions to add overlays and properties to buffers., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 41384768bc 024/115: Merge pull request #1 from syohex/fix-typo, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer e4ec4daa87 027/115: replace-match now returns marker to the end of the replacements., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 41ca2908a3 032/115: Added documentation for four functions., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer b7c9738f31 037/115: Update readme for 0.4 release., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 93f64edf1b 046/115: Added support for case-fold-search, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 761ba8e4b7 049/115: Equals and subtract functionality added.,
ELPA Syncer <=
- [elpa] externals/m-buffer a8d5ce9755 050/115: Performance enhancements to subtract., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer fd9d92a0aa 052/115: Added marmalade for noflet., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 8d351bb5fd 054/115: m-buffer-with-current-marker added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer d6701d8ce2 044/115: Remove extraneous dash dependency to dash., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 25c2b37969 071/115: m-buffer-point renamed to m-buffer-at-point., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 5166d21792 081/115: Lentic documentation for m-buffer.el., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 22ef3ac985 005/115: Emacs 24 only!, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer cbd9d12b3d 023/115: Functions for colourizing text. Improved documentation., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 6e8e29e12d 022/115: Fix some typos, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 05846a92bc 035/115: Removed "-data" from m-buffer-match-data., ELPA Syncer, 2022/07/19