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

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

[elpa] externals/m-buffer 27380daef5 018/115: Functions to add overlays


From: ELPA Syncer
Subject: [elpa] externals/m-buffer 27380daef5 018/115: Functions to add overlays and properties to buffers.
Date: Tue, 19 Jul 2022 15:58:45 -0400 (EDT)

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

    Functions to add overlays and properties to buffers.
---
 m-buffer.el           | 43 ++++++++++++++++++++++++++++++++++++++++---
 test/m-buffer-test.el | 10 ++++++++++
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/m-buffer.el b/m-buffer.el
index 3ec9de5641..84d7724a23 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -178,6 +178,14 @@ args, assume they are of the form accepted by
    (t
     (error "Invalid arguments"))))
 
+;;
+;; Match-data manipulation
+;;
+(defun m-buffer-buffer-for-match (match-data)
+  "Given some MATCH-DATA return the buffer that the matches are
+too."
+  (marker-buffer (caar match-data)))
+
 (defun m-buffer-match-nth-group (n match-data)
   "From MATCH-DATA, fetch the match to the nth match group."
   (-map
@@ -470,10 +478,39 @@ MATCH-DATA can be any list of lists with two elements (or 
more)."
    (m-buffer-match-nth-group n match-data)))
 
 ;;
-;; Highlight things
+;; Overlays
 ;;
-
-
+(defun m-buffer-overlay-match (match-data &optional front-advance rear-advance)
+  "Return an overlay for all matches to MATCH-DATA.
+FRONT-ADVANCE and REAR-ADVANCE controls the borders of the
+overlay as defined in `make-overlay'. Overlays do not scale that
+well, so use `m-buffer-propertize-match' if you intend to make
+and keep many of these.
+
+See Info node `(elisp) Overlays' forfurther information.
+"
+  (let ((buffer (m-buffer-buffer-for-match match-data)))
+    (m-buffer-on-region
+     (lambda (beginning end)
+       (make-overlay
+        beginning end buffer
+        front-advance rear-advance))
+     match-data)))
+
+(defun m-buffer-add-text-property-match
+  (match-data properties)
+  (let ((buffer (m-buffer-buffer-for-match match-data)))
+    (m-buffer-on-region
+     (lambda (beginning end)
+       (add-text-property beginning end properties))
+     match-data)))
+
+(defun m-buffer-put-text-property-match (match-data property value)
+  (let ((buffer (m-buffer-buffer-for-match match-data)))
+    (m-buffer-on-region
+     (lambda (beginning end)
+       (put-text-property beginning end property value))
+     match-data)))
 
 (provide 'm-buffer)
 ;;; m-buffer.el ends here
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index a6ede5da68..1397203c4b 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -202,6 +202,16 @@
      (m-buffer-markers-to-pos
       (m-buffer-match-sentence-end (current-buffer)))))))
 
+(ert-deftest buffer-for-match ()
+  (should
+   (with-temp-buffer
+     (progn
+       (insert "a")
+       (equal
+        (current-buffer)
+        (m-buffer-buffer-for-match
+         (m-buffer-match-data (current-buffer) "a")))))))
+
 (ert-deftest match-n ()
   (should
    (equal



reply via email to

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