[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 9eed0b8 2/2: consult--highlight-regexps: Only h
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 9eed0b8 2/2: consult--highlight-regexps: Only highlight capturing groups |
Date: |
Thu, 5 Aug 2021 20:57:07 -0400 (EDT) |
branch: externals/consult
commit 9eed0b89c57a5da8f93ecd77de03655b5345c75e
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
consult--highlight-regexps: Only highlight capturing groups
Orderless uses the same approach.
---
consult.el | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/consult.el b/consult.el
index bb5891f..18ad213 100644
--- a/consult.el
+++ b/consult.el
@@ -614,11 +614,17 @@ ARGS is a list of commands or sources followed by the
list of keyword-value pair
(invalid-regexp nil)))
(defun consult--highlight-regexps (regexps str start)
- "Highlight REGEXPS in STR from START."
+ "Highlight REGEXPS in STR from START.
+If a regular expression contains capturing groups, only these are highlighted.
+If no capturing groups are used highlight the whole match."
(save-match-data
(dolist (re regexps)
(when (string-match re str start)
- (put-text-property (match-beginning 0) (match-end 0) 'face
'consult-preview-match str)))))
+ (let ((i (if (match-beginning 1) 1 0)))
+ (while (match-beginning i)
+ (add-face-text-property (match-beginning i) (match-end i)
+ 'consult-preview-match nil str)
+ (setq i (1+ i))))))))
(defun consult--regexp-filter (regexps)
"Create filter regexp from REGEXPS."