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

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

[elpa] master bf8dc5f 326/348: Make swiper-avy work with more regexp bui


From: Oleh Krehel
Subject: [elpa] master bf8dc5f 326/348: Make swiper-avy work with more regexp builders
Date: Sat, 8 Apr 2017 11:04:24 -0400 (EDT)

branch: master
commit bf8dc5f778cbac27629162e07f798032310552cf
Author: Dale Sedivec <address@hidden>
Commit: Dale Sedivec <address@hidden>

    Make swiper-avy work with more regexp builders
    
    Previously, if you were using regexp builders such as ivy--regex-fuzzy
    or ivy--regex-ignore-order, or anything for which ivy--regex doesn't
    produce a useful match, swiper-avy would not find candidates in the
    window where you invoked swiper.  These changes leverage the existing
    overlays in the window, which were presumably added with the help of
    your chosen regexp builder, to find candidates for Avy.
---
 swiper.el | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/swiper.el b/swiper.el
index f8a9fce..ce7c07c 100644
--- a/swiper.el
+++ b/swiper.el
@@ -156,10 +156,28 @@
     (error "Package avy isn't installed"))
   (unless (string= ivy-text "")
     (let* ((avy-all-windows nil)
+           ;; We'll have overlapping overlays, so we sort all the
+           ;; overlays in the visible region by their start, and then
+           ;; throw out non-Swiper overlays or overlapping Swiper
+           ;; overlays.
+           (visible-overlays (cl-sort (with-ivy-window
+                                        (overlays-in (window-start)
+                                                     (window-end)))
+                                      #'< :key #'overlay-start))
+           (min-overlay-start 0)
+           (overlays-for-avy (cl-remove-if-not
+                              (lambda (ov)
+                                (when (and (>= (overlay-start ov)
+                                               min-overlay-start)
+                                           (memq (overlay-get ov 'face)
+                                                 swiper-faces))
+                                  (setq min-overlay-start (overlay-start ov))))
+                              visible-overlays))
            (candidates (append
-                        (with-ivy-window
-                          (avy--regex-candidates
-                           (ivy--regex ivy-text)))
+                        (mapcar (lambda (ov)
+                                  (cons (overlay-start ov)
+                                        (overlay-get ov 'window)))
+                                overlays-for-avy)
                         (save-excursion
                           (save-restriction
                             (narrow-to-region (window-start) (window-end))
@@ -192,7 +210,7 @@
             (ivy-done)
             (ivy-call))
         (ivy-quit-and-run
-         (avy-action-goto (caar candidate)))))))
+         (avy-action-goto (avy-candidate-beg candidate)))))))
 
 (declare-function mc/create-fake-cursor-at-point "ext:multiple-cursors-core")
 (declare-function multiple-cursors-mode "ext:multiple-cursors-core")



reply via email to

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