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

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

[elpa] externals/swiper 9393004 3/3: Merge branch 'master' into external


From: Basil L. Contovounesios
Subject: [elpa] externals/swiper 9393004 3/3: Merge branch 'master' into externals/swiper
Date: Fri, 21 May 2021 09:22:23 -0400 (EDT)

branch: externals/swiper
commit 9393004f49d4f1552ed91c6aaa2e6cbeca7375bd
Merge: 6f17f80 a5eade0
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Merge branch 'master' into externals/swiper
---
 swiper.el | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/swiper.el b/swiper.el
index 7e4f7ed..fe4fbb7 100644
--- a/swiper.el
+++ b/swiper.el
@@ -332,19 +332,28 @@ If the input is empty, select the previous history 
element instead."
            (avy-push-mark))
       (avy--done))))
 
+(defun swiper--avy-index (pos)
+  "Return `ivy--index' for `avy' candidate at minibuffer POS."
+  ;; Position in original buffer.
+  (let ((opos (get-text-property pos 'point)))
+    (or
+     ;; Find `swiper-isearch' index based on buffer position.
+     (and opos (cl-position opos ivy--all-candidates))
+     ;; Find `swiper' index based on line number.
+     (let ((nlines (count-lines (point-min) (point-max))))
+       (+ (car (ivy--minibuffer-index-bounds
+                ivy--index ivy--length ivy-height))
+          (line-number-at-pos pos)
+          (if (or (= nlines (1+ ivy-height))
+                  (< ivy--length ivy-height))
+              0
+            (- ivy-height nlines))
+          -2)))))
+
 (defun swiper--avy-goto (candidate)
   (cond ((let ((win (cdr-safe candidate)))
            (and win (window-minibuffer-p win)))
-         (let ((nlines (count-lines (point-min) (point-max))))
-           (ivy-set-index
-            (+ (car (ivy--minibuffer-index-bounds
-                     ivy--index ivy--length ivy-height))
-               (line-number-at-pos (car candidate))
-               (if (or (= nlines (1+ ivy-height))
-                       (< ivy--length ivy-height))
-                   0
-                 (- ivy-height nlines))
-               -2)))
+         (setq ivy--index (swiper--avy-index (car candidate)))
          (ivy--exhibit)
          (ivy-done)
          (ivy-call))
@@ -355,16 +364,19 @@ If the input is empty, select the previous history 
element instead."
 
 ;;;###autoload
 (defun swiper-avy ()
-  "Jump to one of the current swiper candidates."
+  "Jump to one of the current swiper candidates with `avy'."
   (interactive)
   (unless (require 'avy nil 'noerror)
-    (error "Package avy isn't installed"))
+    (user-error "Package avy isn't installed"))
   (cl-case (length ivy-text)
     (0
      (user-error "Need at least one char of input"))
     (1
-     (let ((swiper-min-highlight 1))
-       (swiper--update-input-ivy))))
+     ;; FIXME: `swiper--update-input-ivy' expects string candidates,
+     ;; but `swiper-isearch' now uses buffer positions.
+     (when (stringp (ivy-state-current ivy-last))
+       (let ((swiper-min-highlight 1))
+         (swiper--update-input-ivy)))))
   (swiper--avy-goto (swiper--avy-candidate)))
 
 (declare-function mc/create-fake-cursor-at-point "ext:multiple-cursors-core")



reply via email to

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