summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Antolín <omar.antolin@gmail.com>2020-04-15 17:53:28 -0500
committerOmar Antolín <omar.antolin@gmail.com>2020-04-15 17:53:28 -0500
commitc9ae65ea165712369d33647a6c636d6bc95bcc29 (patch)
tree08560fa74747b2984ea1ba1c5f40bb0de95f62d6
parent6aabc83f02b3502c1f4df66616e8ad1ee53e382e (diff)
Highlight component matches in one of four faces
-rw-r--r--orderless.el46
1 files changed, 36 insertions, 10 deletions
diff --git a/orderless.el b/orderless.el
index c7b6e1c..9ad70ef 100644
--- a/orderless.el
+++ b/orderless.el
@@ -45,14 +45,40 @@
;;; Code:
-(defun orderless--highlight-match (regexp string)
- ;; only call this when the match has already been checked!
- (string-match regexp string)
- (font-lock-prepend-text-property
- (match-beginning 0)
- (match-end 0)
- 'face 'completions-common-part
- string))
+(require 'cl-lib)
+
+(defgroup orderless nil
+ "Completion method that matches space-separated regexps in any order."
+ :group 'completion)
+
+(defface orderless-match-face-0 '((t :background "#5ada88"))
+ "Face for maches of components numbered 0 mod 4."
+ :group 'orderless)
+
+(defface orderless-match-face-1 '((t :background "#d5baff"))
+ "Face for maches of components numbered 1 mod 4."
+ :group 'orderless)
+
+(defface orderless-match-face-2 '((t :background "#6aaeff"))
+ "Face for maches of components numbered 2 mod 4."
+ :group 'orderless)
+
+(defface orderless-match-face-3 '((t :background "#ff8892"))
+ "Face for maches of components numbered 3 mod 4."
+ :group 'orderless)
+
+(let ((faces [orderless-match-face-0
+ orderless-match-face-1
+ orderless-match-face-2
+ orderless-match-face-3]))
+ (defun orderless--highlight-match (regexp string face)
+ ;; only call this when the match has already been checked!
+ (string-match regexp string)
+ (font-lock-prepend-text-property
+ (match-beginning 0)
+ (match-end 0)
+ 'face (aref faces (mod face 4))
+ string)))
(defun orderless-all-completions (string table pred _point)
(save-match-data
@@ -71,9 +97,9 @@
always (string-match-p regexp original))
collect ; it's a match, copy and highlight
(cl-loop with candidate = (copy-sequence original)
- for regexp in regexps do
+ for regexp in regexps and face from 0 do
(orderless--highlight-match
- regexp candidate)
+ regexp candidate face)
finally (return candidate))))
(when all (nconc all (length prefix))))
(invalid-regexp nil)))))