[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
- [elpa] externals/m-buffer ce6dfb0023 006/115: Use Emacs var, (continued)
- [elpa] externals/m-buffer ce6dfb0023 006/115: Use Emacs var, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 84c7fddd48 008/115: Modifed match-data to use keyword args, except for first two args., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 25995a676e 009/115: README added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 22760408a5 013/115: Updated normalize tests to cope with extra widen argument., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 5c46bf8102 017/115: Added function m-buffer-on-region -- apply a function to a region., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 8210f4147d 004/115: Move dev to test., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 650235fbdb 011/115: Build URL update., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 22d6b0d640 012/115: Beginning has become begin. Widen option added. New line matching functions., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer c65b7b20c0 014/115: match-data-1 was failing on final match due to off-by-one error., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 1cc4d8cffb 015/115: Added functions: m-buffer-marker-tree-to-pos, m-buffer-match-nth-group., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 27380daef5 018/115: Functions to add overlays and properties to buffers.,
ELPA Syncer <=
- [elpa] externals/m-buffer 41384768bc 024/115: Merge pull request #1 from syohex/fix-typo, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer e4ec4daa87 027/115: replace-match now returns marker to the end of the replacements., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 41ca2908a3 032/115: Added documentation for four functions., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer b7c9738f31 037/115: Update readme for 0.4 release., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 93f64edf1b 046/115: Added support for case-fold-search, ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 761ba8e4b7 049/115: Equals and subtract functionality added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer a8d5ce9755 050/115: Performance enhancements to subtract., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer fd9d92a0aa 052/115: Added marmalade for noflet., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer 8d351bb5fd 054/115: m-buffer-with-current-marker added., ELPA Syncer, 2022/07/19
- [elpa] externals/m-buffer d6701d8ce2 044/115: Remove extraneous dash dependency to dash., ELPA Syncer, 2022/07/19