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

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

[elpa] master ee5dacf 385/399: Add swiper-backward command


From: Oleh Krehel
Subject: [elpa] master ee5dacf 385/399: Add swiper-backward command
Date: Sat, 20 Jul 2019 14:58:05 -0400 (EDT)

branch: master
commit ee5dacf23cbb82b1557aa00d648aae681f6c6db7
Author: Joel Rosdahl <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add swiper-backward command
    
    Fixes #1172.
---
 ivy.el    | 13 ++++++++++++-
 swiper.el | 11 ++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/ivy.el b/ivy.el
index 4f5a1c2..22ff77c 100644
--- a/ivy.el
+++ b/ivy.el
@@ -3221,7 +3221,8 @@ CANDIDATES are assumed to be static."
         (if (memq (cdr (assq (ivy-state-caller ivy-last)
                              ivy-index-functions-alist))
                   '(ivy-recompute-index-swiper
-                    ivy-recompute-index-swiper-async))
+                    ivy-recompute-index-swiper-async
+                    ivy-recompute-index-swiper-backward))
             (progn
               (ivy--recompute-index name re-str cands)
               (setq ivy--old-cands (ivy--sort name cands)))
@@ -3444,6 +3445,16 @@ CANDS are the current candidates."
               res))))
     (error 0)))
 
+(defun ivy-recompute-index-swiper-backward (re-str cands)
+  "Recompute index of selected candidate when using `swiper-backward'.
+CANDS are the current candidates."
+  (let ((idx (ivy-recompute-index-swiper re-str cands)))
+    (if (or (= idx -1)
+            (<= (read (get-text-property 0 'swiper-line-number (nth idx 
cands)))
+                (line-number-at-pos)))
+        idx
+      (- idx 1))))
+
 (defun ivy-recompute-index-swiper-async (_re-str cands)
   "Recompute index of selected candidate when using `swiper' asynchronously.
 CANDS are the current candidates."
diff --git a/swiper.el b/swiper.el
index 75f8181..6524fd0 100644
--- a/swiper.el
+++ b/swiper.el
@@ -538,12 +538,21 @@ numbers; replaces calculating the width from buffer line 
count."
 
 ;;;###autoload
 (defun swiper (&optional initial-input)
-  "`isearch' with an overview.
+  "`isearch-forward' with an overview.
 When non-nil, INITIAL-INPUT is the initial search pattern."
   (interactive)
   (swiper--ivy (swiper--candidates) initial-input))
 
 ;;;###autoload
+(defun swiper-backward (&optional initial-input)
+  "`isearch-backward' with an overview.
+When non-nil, INITIAL-INPUT is the initial search pattern."
+  (interactive)
+  (let ((ivy-index-functions-alist
+         '((swiper . ivy-recompute-index-swiper-backward))))
+    (swiper initial-input)))
+
+;;;###autoload
 (defun swiper-thing-at-point ()
   "`swiper' with `ivy-thing-at-point'."
   (interactive)



reply via email to

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