From ae36760f610d25693f089dde31b51d4e9c5f9363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Antol=C3=ADn?= Date: Tue, 14 Apr 2020 11:20:59 -0500 Subject: Colorize matching portions of candidates --- orderless.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/orderless.el b/orderless.el index 22ac799..c515056 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)))) -- cgit v1.0