[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 02ca7a1 25/67: Add anchoring
From: |
Oleh Krehel |
Subject: |
[elpa] master 02ca7a1 25/67: Add anchoring |
Date: |
Sun, 22 Mar 2015 17:33:57 +0000 |
branch: master
commit 02ca7a18b478a3e565985ca577548dd5927fc7a3
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add anchoring
* ivy.el (ivy-read): Add optional argument INDEX. It's the index of
initally selected entry.
(ivy-completions): Update.
* swiper.el (swiper--ivy): Call `ivy-read' with `line-number-at-pos'.
Fixes #16
---
ivy.el | 34 ++++++++++++++++++++++------------
swiper.el | 3 ++-
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/ivy.el b/ivy.el
index b0baea9..73965c8 100644
--- a/ivy.el
+++ b/ivy.el
@@ -108,14 +108,16 @@ On error (read-only), quit without selecting."
(minibuffer-keyboard-quit))))
;;** Entry Point
-(defun ivy-read (prompt collection &optional initial-input update-fn)
+(defun ivy-read (prompt collection &optional initial-input update-fn index)
"Read a string in the minibuffer, with completion.
PROMPT is a string to prompt with; normally it ends in a colon and a space.
COLLECTION is a list of strings.
If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.
-UPDATE-FN is called each time the current candidate(s) is changed."
- (setq ivy--index 0)
+UPDATE-FN is called each time the current candidate(s) is changed.
+If INDEX is non-nil select the corresponding candidate."
+ (setq ivy--index (or index 0))
(setq ivy--old-re nil)
+ (setq ivy--old-cands nil)
(setq ivy-text "")
(setq ivy--all-candidates collection)
(setq ivy--update-fn update-fn)
@@ -242,15 +244,23 @@ NAME is a string of words separated by spaces that is
used to
build a regex.
CANDIDATES is a list of strings."
(let* ((re (ivy--regex name))
- (cands (if (equal re ivy--old-re)
+ (cands (if (and (equal re ivy--old-re)
+ ivy--old-cands)
ivy--old-cands
(setq ivy--old-re re)
- (setq ivy--old-cands
- (ignore-errors
- (cl-remove-if-not
- (lambda (x) (string-match re x))
- candidates))))))
+ (ignore-errors
+ (cl-remove-if-not
+ (lambda (x) (string-match re x))
+ candidates))))
+ (tail (nthcdr ivy--index ivy--old-cands))
+ idx)
(setq ivy--length (length cands))
+ (when (and tail ivy--old-cands)
+ (while (and tail
+ (null (setq idx (cl-position (pop tail) cands
+ :test #'equal)))))
+ (setq ivy--index (or idx 0)))
+ (setq ivy--old-cands cands)
;; should do a re-anchor here
(when (>= ivy--index ivy--length)
(setq ivy--index (1- ivy--length)))
@@ -262,9 +272,9 @@ CANDIDATES is a list of strings."
(cl-subseq cands 0 (min (1- ivy-height) ivy--length)))
(setq cands
(cl-subseq cands
- (- index (/ ivy-height 2))
- (min (+ index (/ ivy-height 2))
- ivy--length)))
+ (- index (/ ivy-height 2))
+ (min (+ index (/ ivy-height 2))
+ ivy--length)))
(setq index (min (/ ivy-height 2)
(1- (length cands)))))
(setq ivy--current (copy-sequence
diff --git a/swiper.el b/swiper.el
index dd1f106..4c22eba 100644
--- a/swiper.el
+++ b/swiper.el
@@ -142,7 +142,8 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(setq res (ivy-read "pattern: "
(swiper--candidates)
initial-input
- #'swiper--update-input-ivy))
+ #'swiper--update-input-ivy
+ (1- (line-number-at-pos))))
(ido-mode 1)
(swiper--cleanup)
(if (null ivy-exit)
- [elpa] master 7cea819 18/67: ivy.el: Add `ivy-exit', (continued)
- [elpa] master 7cea819 18/67: ivy.el: Add `ivy-exit', Oleh Krehel, 2015/03/22
- [elpa] master eb1def0 17/67: Add initial-input optional argument, Oleh Krehel, 2015/03/22
- [elpa] master 2f5cc11 15/67: swiper.el: Use `with-selected-window' instead of `with-current-buffer', Oleh Krehel, 2015/03/22
- [elpa] master 02065be 19/67: swiper.el: Restore original point on canceling, Oleh Krehel, 2015/03/22
- [elpa] master 6a874a4 11/67: Add `ivy' back end, Oleh Krehel, 2015/03/22
- [elpa] master f268cc8 21/67: Reveal invisible overlays, Oleh Krehel, 2015/03/22
- [elpa] master 835208a 20/67: Inherit standard faces by default, Oleh Krehel, 2015/03/22
- [elpa] master f148a94 24/67: Fix use of cl-incf, Oleh Krehel, 2015/03/22
- [elpa] master 2ed9ee2 23/67: Require delsel for `minibuffer-keyboard-quit', Oleh Krehel, 2015/03/22
- [elpa] master 1ca1660 22/67: swiper.el: Save position before last search, Oleh Krehel, 2015/03/22
- [elpa] master 02ca7a1 25/67: Add anchoring,
Oleh Krehel <=
- [elpa] master b1ac649 26/67: Don't recenter unless necessary, Oleh Krehel, 2015/03/22
- [elpa] master a07c2e4 27/67: swiper.el: Make ivy the default back end, Oleh Krehel, 2015/03/22
- [elpa] master baa9df7 30/67: Truncate candidates to window width in the minibuffer, Oleh Krehel, 2015/03/22
- [elpa] master 7c6d00d 32/67: ivy.el (ivy-read): Return immediately for less than 2 candidates, Oleh Krehel, 2015/03/22
- [elpa] master 315be36 31/67: counsel.el: Add, Oleh Krehel, 2015/03/22
- [elpa] master 0772929 29/67: Add some rudimentary history handling, Oleh Krehel, 2015/03/22
- [elpa] master 045fb60 28/67: ivy.el (ivy-previous-line): Change to `cl-decf', Oleh Krehel, 2015/03/22
- [elpa] master e1cdb29 37/67: counsel.el: Add Clojure completion at point, Oleh Krehel, 2015/03/22
- [elpa] master 7ff3dd9 35/67: Need to check value of variable, Oleh Krehel, 2015/03/22
- [elpa] master c78cc15 34/67: swiper.el: Clean up overlays better on "C-g", Oleh Krehel, 2015/03/22