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

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

[elpa] master b05ae24 254/399: swiper.el (swiper--add-properties): Extra


From: Oleh Krehel
Subject: [elpa] master b05ae24 254/399: swiper.el (swiper--add-properties): Extract
Date: Sat, 20 Jul 2019 14:57:35 -0400 (EDT)

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

    swiper.el (swiper--add-properties): Extract
---
 swiper.el | 65 ++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/swiper.el b/swiper.el
index 09c51e8..ec73b5e 100644
--- a/swiper.el
+++ b/swiper.el
@@ -899,9 +899,12 @@ WND, when specified is the window."
           ;; greater otherwise. We hope that the inclusion of the
           ;; newline will not ever be a problem in practice.
           (when (< (count-lines (match-beginning 0) (match-end 0)) 2)
-            (let ((faces (if (= (match-end 0) pt)
-                             swiper-faces
-                           swiper-background-faces)))
+            (let* ((faces (if (= (match-end 0) pt)
+                              swiper-faces
+                            swiper-background-faces))
+                   (adder-fn (lambda (beg end face priority)
+                               (push (swiper--make-overlay beg end face wnd 
priority)
+                                     isearch-lazy-highlight-overlays))))
               (unless (and (consp ivy--old-re)
                            (null
                             (save-match-data
@@ -910,33 +913,35 @@ WND, when specified is the window."
                                                (buffer-substring-no-properties
                                                 (line-beginning-position)
                                                 (line-end-position)))))))
-                (let ((mb (match-beginning 0))
-                      (me (match-end 0)))
-                  (unless (> (- me mb) 2017)
-                    (push (swiper--make-overlay mb me
-                                                (if (zerop ivy--subexps)
-                                                    (cadr faces)
-                                                  (car faces))
-                                                wnd 0)
-                          isearch-lazy-highlight-overlays))))
-              (let ((i 1)
-                    (j 0))
-                (while (<= (cl-incf j) ivy--subexps)
-                  (let ((bm (match-beginning j))
-                        (em (match-end j)))
-                    (when (and (integerp em)
-                               (integerp bm))
-                      (while (and (< j ivy--subexps)
-                                  (integerp (match-beginning (+ j 1)))
-                                  (= em (match-beginning (+ j 1))))
-                        (setq em (match-end (cl-incf j))))
-                      (push (swiper--make-overlay
-                             bm em
-                             (nth (1+ (mod (+ i 2) (1- (length faces))))
-                                  faces)
-                             wnd i)
-                            isearch-lazy-highlight-overlays)
-                      (cl-incf i))))))))))))
+                (swiper--add-properties faces adder-fn)))))))))
+
+(defun swiper--add-properties (faces adder-fn)
+  (let ((mb (match-beginning 0))
+        (me (match-end 0)))
+    (unless (> (- me mb) 2017)
+      (funcall adder-fn
+               mb me
+               (if (zerop ivy--subexps)
+                   (cadr faces)
+                 (car faces))
+               0)))
+  (let ((i 1)
+        (j 0))
+    (while (<= (cl-incf j) ivy--subexps)
+      (let ((bm (match-beginning j))
+            (em (match-end j)))
+        (when (and (integerp em)
+                   (integerp bm))
+          (while (and (< j ivy--subexps)
+                      (integerp (match-beginning (+ j 1)))
+                      (= em (match-beginning (+ j 1))))
+            (setq em (match-end (cl-incf j))))
+          (funcall adder-fn
+                   bm em
+                   (nth (1+ (mod (+ i 2) (1- (length faces))))
+                        faces)
+                   i)
+          (cl-incf i))))))
 
 (defcustom swiper-action-recenter nil
   "When non-nil, recenter after exiting `swiper'."



reply via email to

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