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

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

[elpa] externals/m-buffer c2ea6f72b9 060/115: m-buffer-first-line added.


From: ELPA Syncer
Subject: [elpa] externals/m-buffer c2ea6f72b9 060/115: m-buffer-first-line added.
Date: Tue, 19 Jul 2022 15:58:48 -0400 (EDT)

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

    m-buffer-first-line added.
    
    New method to find the first line.
---
 m-buffer.el           | 15 ++++++++++++++-
 test/m-buffer-test.el | 16 +++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/m-buffer.el b/m-buffer.el
index e9da454f49..3d43710775 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -540,13 +540,17 @@ MATCH is of form BUFFER-OR-WINDOW MATCH-OPTIONS. See
    'm-buffer-match match :regexp paragraph-separate
    :post-match 'm-buffer-post-match-forward-line))
 
+(defvar m-buffer--line-regexp
+  "^.*$"
+  "Regexp to match a line.")
+
 (defun m-buffer-match-line (&rest match)
   "Return a list of match data to all lines.
 MATCH is of the form BUFFER-OR-WINDOW MATCH-OPTIONS.
 See `m-buffer-match for further details."
   (m-buffer-apply-snoc
    'm-buffer-match
-   match :regexp "^.*$"
+   match :regexp m-buffer--line-regexp
    :post-match 'm-buffer-post-match-forward-char))
 
 (defun m-buffer-match-line-start (&rest match)
@@ -567,6 +571,15 @@ MATCH is of form BUFFER-OR-WINDOW MATCH-OPTIONS. See
    match :regexp "$"
    :post-match 'm-buffer-post-match-forward-char))
 
+(defun m-buffer-match-first-line (&rest match)
+  "Returns a match to the first line of MATCH.
+This matches more efficiently than matching all lines and taking
+the car. See `m-buffer-match' for further details of MATCH."
+  (m-buffer-apply-snoc
+   'm-buffer-match match
+   :regexp m-buffer--line-regexp
+   :post-match (lambda () nil)))
+
 (defun m-buffer-match-sentence-end (&rest match)
   "Return a list of match to sentence end.
 MATCH is of the form BUFFER-OR-WINDOW MATCH-OPTIONS. See
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 1b4ae9aa40..a0e9ae3eea 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -203,9 +203,19 @@
    (equal
     '(1 2 4 6 9 12 13)
     (m-buffer-wtb-of-file
-       "line-start.txt"
-       (m-buffer-marker-to-pos
-        (m-buffer-match-line-end (current-buffer)))))))
+     "line-start.txt"
+     (m-buffer-marker-to-pos
+      (m-buffer-match-line-end (current-buffer)))))))
+
+(ert-deftest first-line ()
+  (should
+   (equal
+    '((1 1))
+    (m-buffer-wtb-of-file
+     "line-start.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match-first-line
+       (current-buffer)))))))
 
 (ert-deftest sentence-end ()
   (should



reply via email to

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