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

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

[elpa] externals/m-buffer 93f64edf1b 046/115: Added support for case-fol


From: ELPA Syncer
Subject: [elpa] externals/m-buffer 93f64edf1b 046/115: Added support for case-fold-search
Date: Tue, 19 Jul 2022 15:58:47 -0400 (EDT)

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

    Added support for case-fold-search
    
    Previously, case-fold-search could be set externally, but is now also
    offered as an argument.
---
 m-buffer.el           | 26 +++++++++++++++++++++-----
 test/case-match.txt   |  4 ++++
 test/m-buffer-test.el | 51 +++++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 66 insertions(+), 15 deletions(-)

diff --git a/m-buffer.el b/m-buffer.el
index 78d7c983cc..31dbd13d08 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -64,6 +64,7 @@ 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
 
 If options are expressed in two places, the plist form takes
 precedence over positional args. So calling with both a first
@@ -77,7 +78,8 @@ this. The buffer is searched forward."
   (apply 'm-buffer-match-1
          (m-buffer-normalize-args match)))
 
-(defun m-buffer-match-1 (buffer regexp begin end post-match widen)
+(defun m-buffer-match-1 (buffer regexp begin end
+                                post-match widen cfs)
   "Return a list of `match-data' for all matches.
 
 This is an internal function: please prefer `m-buffer-match'.
@@ -89,7 +91,8 @@ END -- the end of the region to search
 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."
+WIDEN -- call widen first.
+CFS -- Non-nil if searches and matches should ignore case."
   (save-match-data
     (save-excursion
       (save-restriction
@@ -98,7 +101,12 @@ WIDEN -- call widen first."
           (when widen (widen))
           (let ((rtn nil)
                 (post-match-return t)
-                (end-bound (or end (point-max))))
+                (end-bound (or end (point-max)))
+                ;; over-ride default if necessary
+                (case-fold-search
+                 (if (eq :missing cfs)
+                     case-fold-search
+                   cfs)))
             (goto-char
              (or begin
                  (point-min)))
@@ -162,8 +170,16 @@ This is an internal function."
 
          ;; widen
          (widen
-           (plist-get pargs :widen)))
-    (list buffer regexp begin end post-match widen)))
+           (plist-get pargs :widen))
+
+         ;; case-fold-search this needs to overwrite the buffer contents iff
+         ;; set, otherwise be ignore, so we need to distinguish a missing
+         ;; property and a nil one
+         (cfs
+          (if (plist-member pargs :case-fold-search)
+              (plist-get pargs :case-fold-search)
+            :missing)))
+    (list buffer regexp begin end post-match widen cfs)))
 
 (defun m-buffer-ensure-match (&rest match)
   "Ensure that we have match data.
diff --git a/test/case-match.txt b/test/case-match.txt
new file mode 100644
index 0000000000..062fdf1db1
--- /dev/null
+++ b/test/case-match.txt
@@ -0,0 +1,4 @@
+A
+a
+A
+a
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 889f12f739..9ab8330c66 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -56,32 +56,28 @@
   ;; just buffer and regexp
   (should
    (equal
-    (list (current-buffer) "regexp" nil nil nil nil)
+    (list (current-buffer) "regexp" nil nil nil nil :missing)
     (m-buffer-normalize-args
      (list (current-buffer) "regexp"))))
 
   (should
    (equal
-    (list (current-buffer) "regexp" nil nil nil nil)
+    (list (current-buffer) "regexp" nil nil nil nil :missing)
     (m-buffer-normalize-args
      (list (current-buffer) :regexp "regexp"))))
 
   (should
    (equal
-    (list (current-buffer) "regexp" 1 2 3 4)
+    (list (current-buffer) "regexp" 1 2 3 4 :missing)
     (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)
+    (list (current-buffer) "regexp" 1 2 3 4 5)
     (m-buffer-normalize-args
-     (list :buffer (current-buffer)
-           :regexp "regexp"
-           :begin 1
-           :end 2
-           :post-match 3
-           :widen 4)))))
+     (list (current-buffer) "regexp" :begin 1 :end 2 :post-match 3
+           :widen 4 :case-fold-search 5)))))
 
 
 (ert-deftest m-buffer-matches ()
@@ -269,4 +265,39 @@
         (buffer-substring-no-properties from to))
       (m-buffer-match-line
        (current-buffer)))))))
+
+(ert-deftest case-fold-search ()
+  ;; match everything -- technically this is dependent on the buffer-local
+  ;; value of case-fold-search
+  (should
+   (equal
+    '((1 2) (3 4) (5 6) (7 8))
+    (m-buffer-wtb-of-file
+     "case-match.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match
+       (current-buffer)
+       "A")))))
+  ;; match just upper case (i.e. cfs nil)
+  (should
+   (equal
+    '((1 2)(5 6))
+    (m-buffer-wtb-of-file
+     "case-match.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match
+       (current-buffer)
+       "A"
+       :case-fold-search nil)))))
+  ;; match all again
+  (should
+   (equal
+    '((1 2) (3 4) (5 6) (7 8))
+    (m-buffer-wtb-of-file
+     "case-match.txt"
+     (m-buffer-marker-tree-to-pos
+      (m-buffer-match
+       (current-buffer)
+       "A"
+       :case-fold-search t))))))
 ;;; m-buffer-test.el ends here



reply via email to

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