emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master d3f1f2c 18/54: Add extra faces for minibuffer highlighting


From: Oleh Krehel
Subject: [elpa] master d3f1f2c 18/54: Add extra faces for minibuffer highlighting
Date: Tue, 29 Sep 2015 14:09:52 +0000

branch: master
commit d3f1f2ce8f9763cea546bbd2717cbcf17b9a0ad7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add extra faces for minibuffer highlighting
    
    * swiper.el (swiper-minibuffer-match-face-1):
    (swiper-minibuffer-match-face-2):
    (swiper-minibuffer-match-face-3):
    (swiper-minibuffer-match-face-4): New defface.
    (swiper-minibuffer-faces): New defvar.
    
    * ivy.el (ivy--format-minibuffer-line): New defun.
    (ivy--format): Use `ivy--format-minibuffer-line'.
---
 ivy.el    |   63 +++++++++++++++++++++++++++++++------------------------------
 swiper.el |   23 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 31 deletions(-)

diff --git a/ivy.el b/ivy.el
index 3534099..5b9239a 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1507,6 +1507,36 @@ This string will be inserted into the minibuffer.")
                s))
      cands "\n")))
 
+(defun ivy--format-minibuffer-line (str)
+  (let ((start 0)
+        (str (copy-sequence str)))
+    (when (eq ivy-display-style 'fancy)
+      (while (and (string-match ivy--old-re str start)
+                  (> (- (match-end 0) (match-beginning 0)) 0))
+        (setq start (match-end 0))
+        (let ((i 0))
+          (while (<= i ivy--subexps)
+            (let ((face
+                   (cond ((zerop ivy--subexps)
+                          (cadr swiper-minibuffer-faces))
+                         ((zerop i)
+                          (car swiper-minibuffer-faces))
+                         (t
+                          (nth (1+ (mod (+ i 2) (1- (length 
swiper-minibuffer-faces))))
+                               swiper-minibuffer-faces)))))
+              (set-text-properties
+               (match-beginning i)
+               (match-end i)
+               `(face ,face)
+               str))
+            (cl-incf i)))))
+    (when (fboundp 'add-face-text-property)
+      (add-face-text-property
+       0 (length str)
+       `(:height ,(face-attribute 'default :height)
+                 :overline nil) nil str))
+    str))
+
 (defun ivy--format (cands)
   "Return a string for CANDS suitable for display in the minibuffer.
 CANDS is a list of strings."
@@ -1520,8 +1550,7 @@ CANDS is a list of strings."
            (end (min (+ start (1- ivy-height)) ivy--length))
            (start (max 0 (min start (- end (1- ivy-height)))))
            (cands (cl-subseq cands start end))
-           (index (- ivy--index start))
-           (re (funcall ivy--regex-function ivy-text)))
+           (index (- ivy--index start)))
       (when ivy--directory
         (setq cands (mapcar (lambda (x)
                               (if (string-match-p "/\\'" x)
@@ -1532,35 +1561,7 @@ CANDS is a list of strings."
       (setf (nth index cands)
             (ivy--add-face ivy--current 'ivy-current-match))
       (setq cands (mapcar
-                   (lambda (s)
-                     (let ((start 0)
-                           (s (copy-sequence s)))
-                       (when (eq ivy-display-style 'fancy)
-                         (while (and (string-match re s start)
-                                     (> (- (match-end 0) (match-beginning 0)) 
0))
-                           (setq start (match-end 0))
-                           (let ((i 0))
-                             (while (<= i ivy--subexps)
-                               (let ((face
-                                      (cond ((zerop ivy--subexps)
-                                             (cadr swiper-faces))
-                                            ((zerop i)
-                                             (car swiper-faces))
-                                            (t
-                                             (nth (1+ (mod (+ i 2) (1- (length 
swiper-faces))))
-                                                  swiper-faces)))))
-                                 (set-text-properties
-                                  (match-beginning i)
-                                  (match-end i)
-                                  `(face ,face)
-                                  s))
-                               (cl-incf i)))))
-                       (when (fboundp 'add-face-text-property)
-                         (add-face-text-property
-                          0 (length s)
-                          `(:height ,(face-attribute 'default :height)
-                                    :overline nil) nil s))
-                       s))
+                   #'ivy--format-minibuffer-line
                    cands))
       (let* ((ivy--index index)
              (res (concat "\n" (funcall ivy-format-function cands))))
diff --git a/swiper.el b/swiper.el
index 6576ab3..c97f9c8 100644
--- a/swiper.el
+++ b/swiper.el
@@ -61,6 +61,22 @@
   '((t (:inherit isearch-fail)))
   "Face for `swiper' matches modulo 3.")
 
+(defface swiper-minibuffer-match-face-1
+    '((t (:inherit isearch-lazy-highlight-face)))
+  "The background face for `swiper' minibuffer matches.")
+
+(defface swiper-minibuffer-match-face-2
+    '((t (:inherit isearch)))
+  "Face for `swiper' minibuffer matches modulo 1.")
+
+(defface swiper-minibuffer-match-face-3
+    '((t (:inherit match)))
+  "Face for `swiper' minibuffer matches modulo 2.")
+
+(defface swiper-minibuffer-match-face-4
+    '((t (:inherit isearch-fail)))
+  "Face for `swiper' minibuffer matches modulo 3.")
+
 (defface swiper-line-face
   '((t (:inherit highlight)))
   "Face for current `swiper' line.")
@@ -71,6 +87,13 @@
                           swiper-match-face-4)
   "List of `swiper' faces for group matches.")
 
+(defcustom swiper-minibuffer-faces
+  '(swiper-minibuffer-match-face-1
+    swiper-minibuffer-match-face-2
+    swiper-minibuffer-match-face-3
+    swiper-minibuffer-match-face-4)
+  "List of `swiper' faces for minibuffer group matches.")
+
 (defcustom swiper-min-highlight 2
   "Only highlight matches for regexps at least this long."
   :type 'integer)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]