[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/m-buffer ea281db21a 089/115: New function: m-buffer-par
From: |
ELPA Syncer |
Subject: |
[elpa] externals/m-buffer ea281db21a 089/115: New function: m-buffer-partition-by-marker. |
Date: |
Tue, 19 Jul 2022 15:58:51 -0400 (EDT) |
branch: externals/m-buffer
commit ea281db21af0dd48ba08f7f8e0cd2902acdf5a96
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>
New function: m-buffer-partition-by-marker.
---
m-buffer.el | 32 ++++++++++++++++++++++++++++++++
test/m-buffer-test.el | 14 ++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/m-buffer.el b/m-buffer.el
index 21e8efae60..948033282f 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -405,6 +405,8 @@ function. See `m-buffer-nil-marker' for details."
;; ** Match Utility and Predicates
+;; *** Subtraction
+
;; Some predicates and the ability to subtract to lists of matches from each
;; other. This makes up for limitations in Emacs regexp which can't do "match x
;; but not y".
@@ -492,6 +494,36 @@ in M."
matches))
;; #+end_src
+
+;; *** Partition
+
+;; Partition one set of markers by another. This is useful for finding matched
+;; pairs of markers.
+
+;; #+begin_src emacs-lisp
+(defun m-buffer--split-partition (partition)
+ (let ((current nil))
+ (lambda (n)
+ (when
+ (and partition
+ (<= (car partition) n))
+ (setq current (car partition))
+ (setq partition (-drop 1 partition)))
+ current)))
+
+(defun m-buffer-partition-by-marker (list partition)
+ "Given LIST of markers, split at markers in PARTITION.
+Returns a list of lists. The first element of each list is nil or
+the marker from PARTITION. The rest of the elements are those
+elements in LIST which are at the same position or later in the
+buffer than the element from PARTITION, but before the next
+element from PARTITION.
+
+Both LIST and PARTITION must be sorted."
+ (-group-by (m-buffer--split-partition partition) list))
+;; #+end_src
+
+
;; ** Marker manipulation functions
;; These functions do things to markers rather than the areas of the buffers
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index f81763fdef..afe828374b 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -407,4 +407,18 @@ should not have moved."
(m-buffer-match-word
(current-buffer) :regexp "notword")))
+
+(ert-deftest partition-by-markers ()
+ (should
+ (equal
+ '((nil 1)
+ (2 2 3 4)
+ (5 5 6 7)
+ (8 8 9))
+ (m-buffer-partition-by-marker
+ '(1 2 3 4 5 6 7 8 9)
+ '(2 5 8)
+ ))))
+
+
;;; m-buffer-test.el ends here
- [elpa] externals/m-buffer c2ea6f72b9 060/115: m-buffer-first-line added., (continued)
- [elpa] externals/m-buffer c2ea6f72b9 060/115: m-buffer-first-line added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 63a46e6732 063/115: m-buffer-in-match-p added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 3df675024f 064/115: New functions added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 69cf1fb326 066/115: Documentation updates., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer e80fd6cdaa 068/115: Documentation updates., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer e9f9b0819f 072/115: Prepare for next iteration!, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 8c7f63ee16 073/115: Removed pointless call to m-buffer-buffer-for-match., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 77067c0ff5 076/115: Version 0.9 Released., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 3136ab48a8 082/115: Docstring typo., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer c0946dbe6c 085/115: Documentations updates., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer ea281db21a 089/115: New function: m-buffer-partition-by-marker.,
ELPA Syncer <=
- [elpa] externals/m-buffer 3fd8848e40 091/115: m-buffer-at-narrowed-p added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 3702262fbc 092/115: m-buffer was not stateless at all!, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 1f9cb91594 095/115: Generic language., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 3325bfcf6e 098/115: Prepare for next release., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 62751a56db 099/115: Fix hyperlink in travis-ci build., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 1ff021c5f6 100/115: v0.13 release., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 2a056e6248 104/115: seq replaces the dependency on dash., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 61d1ed99e5 103/115: Update email, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 1da2438bfb 105/115: Lentic doc update and generation, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 9c45387989 107/115: Update Cask file for lentic-doc changes, ELPA Syncer, 2022/07/19