[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/anzu 494f1d9d39 195/288: Support highlighting match groups
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/anzu 494f1d9d39 195/288: Support highlighting match groups |
Date: |
Thu, 6 Jan 2022 03:58:52 -0500 (EST) |
branch: elpa/anzu
commit 494f1d9d399d8fa10e97c25dad7c30bcec61f0a4
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>
Support highlighting match groups
---
anzu.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 52 insertions(+), 5 deletions(-)
diff --git a/anzu.el b/anzu.el
index 373d3853f4..4a3cae247a 100644
--- a/anzu.el
+++ b/anzu.el
@@ -110,6 +110,33 @@
"highlight of replaced string"
:group 'anzu)
+(defface anzu-match-1
+ '((((class color) (background light))
+ :background "aquamarine" :foreground "black")
+ (((class color) (background dark))
+ :background "limegreen" :foreground "black")
+ (t :inverse-video t))
+ "First group of match."
+ :group 'anzu)
+
+(defface anzu-match-2
+ '((((class color) (background light))
+ :background "springgreen" :foreground "black")
+ (((class color) (background dark))
+ :background "yellow" :foreground "black")
+ (t :inverse-video t))
+ "Second group of match."
+ :group 'anzu)
+
+(defface anzu-match-3
+ '((((class color) (background light))
+ :background "yellow" :foreground "black")
+ (((class color) (background dark))
+ :background "aquamarine" :foreground "black")
+ (t :inverse-video t))
+ "Third group of match."
+ :group 'anzu)
+
(defface anzu-replace-to
'((((class color) (background light))
:foreground "red")
@@ -314,11 +341,31 @@
(set-marker m beg buf)
(push m anzu--replaced-markers)))
+(defun anzu--make-overlay (begin end face prio)
+ (let ((ov (make-overlay begin end)))
+ (overlay-put ov 'face face)
+ (overlay-put ov 'priority prio)
+ (overlay-put ov 'anzu-overlay t)
+ ov))
+
+(defun anzu--add-match-group-overlay (match-data groups)
+ (when (>= groups 3)
+ (anzu--make-overlay (cl-fifth match-data) (cl-sixth match-data)
+ 'anzu-match-3 1001))
+ (when (>= groups 2)
+ (anzu--make-overlay (cl-third match-data) (cl-fourth match-data)
+ 'anzu-match-2 1001))
+ (anzu--make-overlay (cl-first match-data) (cl-second match-data)
+ 'anzu-match-1 1001))
+
(defun anzu--add-overlay (beg end)
- (let ((ov (make-overlay beg end)))
- (overlay-put ov 'from-string (buffer-substring-no-properties beg end))
- (overlay-put ov 'face 'anzu-replace-highlight)
- (overlay-put ov 'anzu-replace t)))
+ (let* ((match-data (match-data))
+ (groups (/ (- (length match-data) 2) 2)))
+ (when (>= groups 1)
+ (anzu--add-match-group-overlay (cddr match-data) groups))
+ (let ((ov (anzu--make-overlay beg end 'anzu-replace-highlight 1000)))
+ (overlay-put ov 'from-string (buffer-substring-no-properties beg end))
+ (overlay-put ov 'anzu-replace t))))
(defsubst anzu--cleanup-markers ()
(mapc (lambda (m) (set-marker m nil)) anzu--replaced-markers)
@@ -405,7 +452,7 @@
(defun anzu--clear-overlays (buf beg end)
(with-current-buffer buf
(dolist (ov (overlays-in (or beg (point-min)) (or end (point-max))))
- (when (overlay-get ov 'anzu-replace)
+ (when (overlay-get ov 'anzu-overlay)
(delete-overlay ov)))))
(defun anzu--transform-from-to-history ()
- [nongnu] elpa/anzu dcd8eac2e5 165/288: Bump up version and update Changes, (continued)
- [nongnu] elpa/anzu dcd8eac2e5 165/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 57bad64f1e 185/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 7fb133e847 180/288: Fix zero width replacement such as '^'(#44), ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu c3c9a0b721 209/288: Set anzu--status per buffer, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 4ab2b65dcb 201/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 97976620ae 222/288: Merge pull request #64 from akicho8/fix-region-word-replace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f29278e5bd 218/288: Silence byte-compiler, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 31f70860ef 220/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 5684b4b601 199/288: Check replaced regexp is valid, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 3e34fb3df5 279/288: update anzu--use-result-cache-p as in PR #93, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 494f1d9d39 195/288: Support highlighting match groups,
ELPA Syncer <=
- [nongnu] elpa/anzu 12612a2b4f 202/288: Update document of custom function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 27e3a89622 203/288: Correct misspellings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu b80dc0ca92 210/288: Merge pull request #59 from syohex/buffer-local-status, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a08ff2f7db 215/288: Wrap migemo-forward with ignore-errors, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f2aad769c1 227/288: Update copyright year, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu ff54963946 232/288: Merge pull request #67 from syohex/refactoring, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 116501bf9e 216/288: Merge pull request #62 from syohex/fix-migemo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu a35649e401 017/288: Update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu 84183d2a79 022/288: update document, ELPA Syncer, 2022/01/06
- [nongnu] elpa/anzu f4618cd335 023/288: Bump up version and update Changes, ELPA Syncer, 2022/01/06