branch: master
commit eb1def0a6b2cb85a68944b43db3ba612bbeb31e2
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Add initial-input optional argument
* swiper.el (swiper): Update.
(swiper--ivy): Update.
(swiper--helm): Update.
* ivy.el (ivy-read): Update.
Fixes #8.
---
ivy.el | 5 +++--
swiper.el | 21 +++++++++++++--------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/ivy.el b/ivy.el
index 45a8700..e4c7fe0 100644
--- a/ivy.el
+++ b/ivy.el
@@ -106,10 +106,11 @@ On error (read-only), quit without selecting."
(minibuffer-keyboard-quit))))
;;** Entry Point
-(defun ivy-read (prompt collection &optional update-fn)
+(defun ivy-read (prompt collection &optional initial-input update-fn)
"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)
(setq ivy--old-re nil)
@@ -119,7 +120,7 @@ UPDATE-FN is called each time the current candidate(s) is
changed."
(unwind-protect
(minibuffer-with-setup-hook
#'ivy--minibuffer-setup
- (read-from-minibuffer prompt))
+ (read-from-minibuffer prompt initial-input))
(remove-hook 'post-command-hook #'ivy--exhibit)))
(defvar ivy-text ""
diff --git a/swiper.el b/swiper.el
index 6970968..afc1642 100644
--- a/swiper.el
+++ b/swiper.el
@@ -111,13 +111,14 @@
"Allows you to go to next and previous hit isearch-style.")
;;;###autoload
-(defun swiper ()
- "`isearch' with an overview."
+(defun swiper (&optional initial-input)
+ "`isearch' with an overview.
+When non-nil, INITIAL-INPUT is the initial search pattern."
(interactive)
(if (and (eq 'swiper-completion-method 'helm)
(featurep 'helm))
- (swiper--helm)
- (swiper--ivy)))
+ (swiper--helm initial-input)
+ (swiper--ivy initial-input)))
(defun swiper--init ()
"Perform initialization common to both completion methods."
@@ -126,14 +127,16 @@
(setq swiper--anchor (line-number-at-pos))
(setq swiper--window (selected-window)))
-(defun swiper--ivy ()
- "`isearch' with an overview using `ivy'."
+(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)
(unwind-protect
(let ((res (ivy-read "pattern: "
(swiper--candidates)
+ initial-input
#'swiper--update-input-ivy)))
(goto-char (point-min))
(forward-line (1- (read res)))
@@ -144,8 +147,9 @@
(ido-mode 1)
(swiper--cleanup)))
-(defun swiper--helm ()
- "`isearch' with an overview using `helm'."
+(defun swiper--helm (&optional initial-input)
+ "`isearch' with an overview using `helm'.
+When non-nil, INITIAL-INPUT is the initial search pattern."
(interactive)
(require 'helm)
(swiper--init)
@@ -176,6 +180,7 @@
:keymap (make-composed-keymap
swiper-helm-keymap
helm-map)
+ :input initial-input
:preselect
(format "^%d " swiper--anchor)
:buffer "*swiper*"))