[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3a08a88 50/67: ivy.el (ivy-read): Change index to preselec
From: |
Oleh Krehel |
Subject: |
[elpa] master 3a08a88 50/67: ivy.el (ivy-read): Change index to preselect |
Date: |
Sun, 22 Mar 2015 17:34:07 +0000 |
branch: master
commit 3a08a883dba1ed8bf548613d01831898cea5bc11
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-read): Change index to preselect
* ivy.el (ivy-read): Update signature. Instead of giving the integer
index of what to preselect, give a string to preselect.
(ivy--preselect-index): New defun.
* swiper.el (swiper--index-at-point): Rename to `ivy--preselect-index'.
(swiper--ivy): Simplify.
---
ivy.el | 29 ++++++++++++++++++++++++++---
swiper.el | 35 ++++++++++-------------------------
2 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/ivy.el b/ivy.el
index 5b2ef39..37c016d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -134,18 +134,28 @@ On error (read-only), quit without selecting."
(minibuffer-keyboard-quit))))
;;** Entry Point
-(defun ivy-read (prompt collection &optional initial-input update-fn index)
+(defun ivy-read (prompt collection &optional initial-input update-fn preselect)
"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.
-If INDEX is non-nil select the corresponding candidate."
+
+If PRESELECT is non-nil select the corresponding candidate out of
+the ones that match INITIAL-INPUT."
(cl-case (length collection)
(0 nil)
(1 (car collection))
(t
- (setq ivy--index (or index 0))
+ (setq ivy--index (or
+ (and preselect
+ (ivy--preselect-index
+ collection initial-input preselect))
+ 0))
(setq ivy--old-re nil)
(setq ivy--old-cands nil)
(setq ivy-text "")
@@ -169,6 +179,19 @@ If INDEX is non-nil select the corresponding candidate."
res)))
(remove-hook 'post-command-hook #'ivy--exhibit)))))
+(defun ivy--preselect-index (candidates initial-input preselect)
+ "Return the index in CANDIDATES filtered by INITIAL-INPUT for PRESELECT."
+ (when initial-input
+ (setq candidates
+ (cl-remove-if-not
+ (lambda (x)
+ (string-match initial-input x))
+ candidates)))
+ (cl-position-if
+ (lambda (x)
+ (string-match preselect x))
+ candidates))
+
(defvar ivy-text ""
"Stores the user's string as it is typed in.")
diff --git a/swiper.el b/swiper.el
index fc5dae2..80c2339 100644
--- a/swiper.el
+++ b/swiper.el
@@ -134,42 +134,27 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(setq swiper--anchor (line-number-at-pos))
(setq swiper--window (selected-window)))
-(defun swiper--index-at-point (candidates initial-input)
- "Return the index of current line in CANDIDATES filtered by INITIAL-INPUT."
- (cl-position-if
- `(lambda (x)
- (string-match
- ,(format
- "[0-9]+ *%s"
- (regexp-quote
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))))
- x))
- (cl-remove-if-not
- (lambda (x)
- (string-match initial-input x))
- candidates)))
-
(defun swiper--ivy (&optional initial-input)
"`isearch' with an overview using `ivy'.
When non-nil, INITIAL-INPUT is the initial search pattern."
(interactive)
(ido-mode -1)
(swiper--init)
- (let* ((candidates (swiper--candidates))
- (index (if initial-input
- (swiper--index-at-point
- candidates initial-input)
- (1-
- (line-number-at-pos))))
- res)
+ (let ((candidates (swiper--candidates))
+ (preselect (format
+ "%d *%s"
+ (line-number-at-pos)
+ (regexp-quote
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))))
+ res)
(unwind-protect
(setq res (ivy-read "pattern: "
candidates
initial-input
#'swiper--update-input-ivy
- index))
+ preselect))
(ido-mode 1)
(swiper--cleanup)
(if (null ivy-exit)
- [elpa] master e32bc63 46/67: swiper.el: Fix non-matching lines issue with initial-input, (continued)
- [elpa] master e32bc63 46/67: swiper.el: Fix non-matching lines issue with initial-input, Oleh Krehel, 2015/03/22
- [elpa] master f1672c7 45/67: Add isearch-like history behavior, Oleh Krehel, 2015/03/22
- [elpa] master 41732be 48/67: ivy.el: Return nil when there is no match, Oleh Krehel, 2015/03/22
- [elpa] master 588dab6 49/67: ivy-test.el: Add testing, Oleh Krehel, 2015/03/22
- [elpa] master f754835 47/67: swiper.el: Silence a few compilation warnings, Oleh Krehel, 2015/03/22
- [elpa] master cc4bf75 52/67: README.md: Add build status, Oleh Krehel, 2015/03/22
- [elpa] master 2b8e4e1 53/67: ivy.el: Remove while-no-input, Oleh Krehel, 2015/03/22
- [elpa] master 2191bdb 54/67: ivy.el (ivy-completions): Simplify, Oleh Krehel, 2015/03/22
- [elpa] master d587fa2 51/67: ivy.el (ivy-read): Allow for format-style PROMPT, Oleh Krehel, 2015/03/22
- [elpa] master 9f9c4dc 57/67: swiper-helm.el: Fix typo, Oleh Krehel, 2015/03/22
- [elpa] master 3a08a88 50/67: ivy.el (ivy-read): Change index to preselect,
Oleh Krehel <=
- [elpa] master d2b2813 55/67: swiper-helm.el: Copy all helm stuff here, Oleh Krehel, 2015/03/22
- [elpa] master c4acef9 56/67: swiper.el: Remove the helm bits, Oleh Krehel, 2015/03/22
- [elpa] master 0c85d9a 58/67: Add a custom `ivy-count-format', Oleh Krehel, 2015/03/22
- [elpa] master c2e58e9 59/67: Fix invalid package header line, Oleh Krehel, 2015/03/22
- [elpa] master a275a2a 60/67: Use `font-lock-append-text-property' to non-destructively modify a, Oleh Krehel, 2015/03/22
- [elpa] master 7876619 61/67: Update "C-n" and "C-p" bindings, Oleh Krehel, 2015/03/22
- [elpa] master f20b287 62/67: swiper.el (swiper--init): Set `swiper--opoint', Oleh Krehel, 2015/03/22
- [elpa] master bb6c40c 63/67: swiper.el (swiper-min-highlight): New defcustom, Oleh Krehel, 2015/03/22
- [elpa] master cf71b09 64/67: ivy.el (ivy-wrap): New defcustom, Oleh Krehel, 2015/03/22
- [elpa] master 55414c3 66/67: Update Copyright, Oleh Krehel, 2015/03/22