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

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

[elpa] externals/m-buffer 2803b1f9b6 048/115: Match functions now accept


From: ELPA Syncer
Subject: [elpa] externals/m-buffer 2803b1f9b6 048/115: Match functions now accept a :numeric arg.
Date: Tue, 19 Jul 2022 15:58:47 -0400 (EDT)

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

    Match functions now accept a :numeric arg.
    
    This forces the return of integers rather than markers which saves the
    effort of nil'ing them after, but which cannot be used in replace-matches.
---
 m-buffer.el           | 28 +++++++++++++++++++++-------
 test/m-buffer-test.el | 17 ++++++++++++-----
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/m-buffer.el b/m-buffer.el
index 955fc77dd8..185e35f981 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -64,7 +64,9 @@ following keys:
 :end -- the end of the region to search -- default point max
 :post-match -- function called after a match -- default nil
 :widen -- if true, widen buffer first -- default nil
-:case-fold-search value of `case-fold-search' during search
+:case-fold-search value of `case-fold-search' during search.
+If :default accept the current buffer-local value
+:numeric -- if true, return integers not markers
 
 If options are expressed in two places, the plist form takes
 precedence over positional args. So calling with both a first
@@ -79,7 +81,8 @@ this. The buffer is searched forward."
          (m-buffer-normalize-args match)))
 
 (defun m-buffer-match-1 (buffer regexp begin end
-                                post-match widen cfs)
+                                post-match widen cfs
+                                numeric)
   "Return a list of `match-data' for all matches.
 
 This is an internal function: please prefer `m-buffer-match'.
@@ -92,7 +95,9 @@ POST-MATCH -- function to run after each match
 POST-MATCH is useful for zero-width matches which will otherwise cause
 infinite loop. The buffer is searched forward.
 WIDEN -- call widen first.
-CFS -- Non-nil if searches and matches should ignore case."
+CFS -- Non-nil if searches and matches should ignore case.
+NUMERIC -- Non-nil if we should return integers not markers.
+"
   (save-match-data
     (save-excursion
       (save-restriction
@@ -104,7 +109,7 @@ CFS -- Non-nil if searches and matches should ignore case."
                 (end-bound (or end (point-max)))
                 ;; over-ride default if necessary
                 (case-fold-search
-                 (if (eq :missing cfs)
+                 (if (eq :default cfs)
                      case-fold-search
                    cfs)))
             (goto-char
@@ -122,7 +127,10 @@ CFS -- Non-nil if searches and matches should ignore case."
                   t))
               (setq rtn
                     (cons
-                     (match-data)
+                     (if numeric
+                         (m-buffer-marker-to-pos-nil
+                          (match-data))
+                       (match-data))
                      rtn))
               (when post-match
                 (setq post-match-return (funcall post-match))))
@@ -178,8 +186,14 @@ This is an internal function."
          (cfs
           (if (plist-member pargs :case-fold-search)
               (plist-get pargs :case-fold-search)
-            :missing)))
-    (list buffer regexp begin end post-match widen cfs)))
+            :default))
+         
+         ;; numeric
+         (numeric
+          (plist-get pargs :numeric)))
+
+    
+    (list buffer regexp begin end post-match widen cfs numeric)))
 
 (defun m-buffer-ensure-match (&rest match)
   "Ensure that we have match data.
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 9ab8330c66..63ec642c8e 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -56,28 +56,35 @@
   ;; just buffer and regexp
   (should
    (equal
-    (list (current-buffer) "regexp" nil nil nil nil :missing)
+    (list (current-buffer) "regexp" nil nil nil nil :default nil)
     (m-buffer-normalize-args
      (list (current-buffer) "regexp"))))
 
   (should
    (equal
-    (list (current-buffer) "regexp" nil nil nil nil :missing)
+    (list (current-buffer) "regexp" nil nil nil nil :default nil)
     (m-buffer-normalize-args
      (list (current-buffer) :regexp "regexp"))))
 
   (should
    (equal
-    (list (current-buffer) "regexp" 1 2 3 4 :missing)
+    (list (current-buffer) "regexp" 1 2 3 4 :default nil)
     (m-buffer-normalize-args
      (list (current-buffer) "regexp" :begin 1 :end 2 :post-match 3 :widen 4))))
 
   (should
    (equal
-    (list (current-buffer) "regexp" 1 2 3 4 5)
+    (list (current-buffer) "regexp" 1 2 3 4 5 nil)
     (m-buffer-normalize-args
      (list (current-buffer) "regexp" :begin 1 :end 2 :post-match 3
-           :widen 4 :case-fold-search 5)))))
+           :widen 4 :case-fold-search 5))))
+
+  (should
+   (equal
+    (list (current-buffer) "regexp" 1 2 3 4 5 6)
+    (m-buffer-normalize-args
+     (list (current-buffer) "regexp" :begin 1 :end 2 :post-match 3
+           :widen 4 :case-fold-search 5 :numeric 6)))))
 
 
 (ert-deftest m-buffer-matches ()



reply via email to

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