branch: externals/orderless
commit ae36760f610d25693f089dde31b51d4e9c5f9363
Author: Omar Antolín <[email protected]>
Commit: Omar Antolín <[email protected]>
Colorize matching portions of candidates
---
orderless.el | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/orderless.el b/orderless.el
index 22ac79927e..c5150560f3 100644
--- a/orderless.el
+++ b/orderless.el
@@ -45,6 +45,15 @@
;;; Code:
+(defun orderless-highlight-match (regexp string)
+ (when (string-match regexp string)
+ (font-lock-prepend-text-property
+ (match-beginning 0)
+ (match-end 0)
+ 'face 'completions-common-part
+ string)
+ t))
+
(defun orderless-all-completions (string table pred _point)
(let* ((lim (car (completion-boundaries string table pred "")))
(prefix (substring string 0 lim))
@@ -55,10 +64,12 @@
(condition-case nil
(progn
(setq all
- (cl-loop for candidate in all
- when (cl-loop for regexp in regexps
- always (string-match-p regexp
candidate))
- collect candidate))
+ (save-match-data
+ (cl-loop for candidate in all
+ when (cl-loop for regexp in regexps
+ always (orderless-highlight-match
+ regexp candidate))
+ collect candidate)))
(when all (nconc all (length prefix))))
(invalid-regexp nil))))