[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1fad831 10/22: Change `ivy-read' to a cl-defun
From: |
Oleh Krehel |
Subject: |
[elpa] master 1fad831 10/22: Change `ivy-read' to a cl-defun |
Date: |
Wed, 22 Apr 2015 19:51:49 +0000 |
branch: master
commit 1fad83142ed5512548b0d9e7a927da4145437591
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Change `ivy-read' to a cl-defun
* ivy.el (ivy-read): All args but PROMPT and COLLECTION are now keys.
The existing basic calls to `ivy-read' should still work, the others
need to be updated. It's best to try to use `ivy-completing-read' if
possible, since it conforms to the `completing-read' arguments.
New arguments: REQUIRE-MATCH and HISTORY. If HISTORY is nil, `ivy-history'
is used.
(ivy--sorted-files): Don't try to extend the collection.
(ivy-completing-read): Update.
* swiper.el (swiper--ivy): Update.
* counsel.el (counsel-describe-symbol-history): New defvar.
(counsel-describe-variable): Update the call, require match, use
`counsel-describe-symbol-history'.
(counsel-describe-function): Update the call, require match, use
`counsel-describe-symbol-history'.
* ivy-test.el: Update tests, since zero and one length input doesn't
return immediately any more.
Re #46
---
counsel.el | 26 ++++++++------
ivy-test.el | 6 ---
ivy.el | 115 +++++++++++++++++++++++++++++------------------------------
swiper.el | 9 ++---
4 files changed, 76 insertions(+), 80 deletions(-)
diff --git a/counsel.el b/counsel.el
index 5a2ac72..a99bda8 100644
--- a/counsel.el
+++ b/counsel.el
@@ -66,6 +66,9 @@
(error "Couldn't fild definition of %s"
sym)))))
+(defvar counsel-describe-symbol-history nil
+ "History for `counsel-describe-variable' and `counsel-describe-function'.")
+
(defun counsel-describe-variable (variable &optional buffer frame)
"Forward to (`describe-variable' VARIABLE BUFFER FRAME)."
(interactive
@@ -75,10 +78,7 @@
val)
(setq ivy--action nil)
(setq val (ivy-read
- (if (symbolp v)
- (format
- "Describe variable (default %s): " v)
- "Describe variable: ")
+ "Describe variable: "
(let (cands)
(mapatoms
(lambda (vv)
@@ -86,8 +86,11 @@
(and (boundp vv) (not (keywordp vv))))
(push (symbol-name vv) cands))))
cands)
- nil nil counsel-describe-map preselect
- nil t))
+ :keymap counsel-describe-map
+ :preselect preselect
+ :history 'counsel-describe-symbol-history
+ :require-match t
+ :sort t))
(list (if (equal val "")
v
(intern val)))))
@@ -102,17 +105,18 @@
(preselect (thing-at-point 'symbol))
val)
(setq ivy--action nil)
- (setq val (ivy-read (if fn
- (format "Describe function (default %s): " fn)
- "Describe function: ")
+ (setq val (ivy-read "Describe function: "
(let (cands)
(mapatoms
(lambda (x)
(when (fboundp x)
(push (symbol-name x) cands))))
cands)
- nil nil counsel-describe-map preselect
- nil t))
+ :keymap counsel-describe-map
+ :preselect preselect
+ :history 'counsel-describe-symbol-history
+ :require-match t
+ :sort t))
(list (if (equal val "")
fn (intern val)))))
(unless (eq ivy--action 'counsel--find-symbol)
diff --git a/ivy-test.el b/ivy-test.el
index 957f824..dfc1985 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -45,12 +45,6 @@
(ert-deftest ivy-read ()
(should (equal
- (ivy-read "pattern: " nil)
- nil))
- (should (equal
- (ivy-read "pattern: " '("42"))
- "42"))
- (should (equal
(ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
"C-m")
"blue"))
diff --git a/ivy.el b/ivy.el
index 5ac652c..8619f3e 100644
--- a/ivy.el
+++ b/ivy.el
@@ -375,17 +375,12 @@ Directories come first."
(setq seq (cl-sort seq sort-fn)))
(dolist (dir ivy-extra-directories)
(push dir seq))
- (cl-case (length seq)
- (0
- '("" ""))
- (1
- (cons "" seq))
- (t
- seq)))))
+ seq)))
;;** Entry Point
-(defun ivy-read (prompt collection
- &optional predicate initial-input keymap preselect update-fn
sort)
+(cl-defun ivy-read (prompt collection
+ &key predicate require-match initial-input
+ history preselect keymap update-fn sort)
"Read a string in the minibuffer, with completion.
PROMPT is a string to prompt with; normally it ends in a colon
@@ -406,6 +401,7 @@ UPDATE-FN is called each time the current candidate(s) is
changed.
When SORT is t, refer to `ivy-sort-functions-alist' for sorting."
(setq ivy--directory nil)
+ (setq ivy-require-match require-match)
(setq ivy-window (selected-window))
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
@@ -421,7 +417,7 @@ When SORT is t, refer to `ivy-sort-functions-alist' for
sorting."
(setq coll
(ivy--sorted-files default-directory))
(when initial-input
- (unless (or ivy-require-match
+ (unless (or require-match
(equal initial-input default-directory))
(setq coll (cons initial-input coll)))
(setq initial-input nil)))
@@ -443,57 +439,54 @@ When SORT is t, refer to `ivy-sort-functions-alist' for
sorting."
(<= (length coll) ivy-sort-max-size))
(setq coll (cl-sort (copy-sequence coll) sort-fn)))))
(when preselect
- (unless (or ivy-require-match
+ (unless (or require-match
(all-completions preselect collection))
(setq coll (cons preselect coll))))
- (cl-case (length coll)
- (0 nil)
- (1 (car coll))
- (t
- (setq ivy--index (or
- (and preselect
- (ivy--preselect-index
- coll initial-input preselect))
- 0))
- (setq ivy--old-re nil)
- (setq ivy--old-cands nil)
- (setq ivy-text "")
- (setq ivy--all-candidates coll)
- (setq ivy--update-fn update-fn)
- (setq ivy-exit nil)
- (setq ivy--default (or (thing-at-point 'symbol) ""))
- (setq ivy--prompt
- (cond ((string-match "%.*d" prompt)
- prompt)
- ((string-match "%.*d" ivy-count-format)
- (concat ivy-count-format prompt))
- (ivy--directory
- prompt)
- (t
- nil)))
- (setq ivy--action nil)
- (prog1
- (unwind-protect
- (minibuffer-with-setup-hook
- #'ivy--minibuffer-setup
- (let ((res (read-from-minibuffer
- prompt
- initial-input
- (make-composed-keymap keymap ivy-minibuffer-map)
- nil
- 'ivy-history)))
- (when (eq ivy-exit 'done)
- (pop ivy-history)
- (setq ivy-history
- (cons ivy-text (delete ivy-text ivy-history)))
- res)))
- (remove-hook 'post-command-hook #'ivy--exhibit))
- (when ivy--action
- (funcall ivy--action)))))))
+ (setq ivy--index (or
+ (and preselect
+ (ivy--preselect-index
+ coll initial-input preselect))
+ 0))
+ (setq ivy--old-re nil)
+ (setq ivy--old-cands nil)
+ (setq ivy-text "")
+ (setq ivy--all-candidates coll)
+ (setq ivy--update-fn update-fn)
+ (setq ivy-exit nil)
+ (setq ivy--default (or (thing-at-point 'symbol) ""))
+ (setq ivy--prompt
+ (cond ((string-match "%.*d" prompt)
+ prompt)
+ ((string-match "%.*d" ivy-count-format)
+ (concat ivy-count-format prompt))
+ (ivy--directory
+ prompt)
+ (t
+ nil)))
+ (setq ivy--action nil)
+ (prog1
+ (unwind-protect
+ (minibuffer-with-setup-hook
+ #'ivy--minibuffer-setup
+ (let* ((hist (or history 'ivy-history))
+ (res (read-from-minibuffer
+ prompt
+ initial-input
+ (make-composed-keymap keymap ivy-minibuffer-map)
+ nil
+ hist)))
+ (when (eq ivy-exit 'done)
+ (set hist (cons ivy-text
+ (delete ivy-text
+ (cdr (symbol-value hist)))))
+ res)))
+ (remove-hook 'post-command-hook #'ivy--exhibit))
+ (when ivy--action
+ (funcall ivy--action)))))
(defun ivy-completing-read (prompt collection
&optional predicate require-match initial-input
- _history def _inherit-input-method)
+ history def _inherit-input-method)
"Read a string in the minibuffer, with completion.
This is an interface that conforms to `completing-read', so that
@@ -512,8 +505,14 @@ _INHERIT-INPUT-METHOD is ignored for now.
The history, defaults and input-method arguments are ignored for now."
(when (listp def)
(setq def (car def)))
- (setq ivy-require-match require-match)
- (ivy-read prompt collection predicate initial-input nil def nil t))
+ (ivy-read prompt collection
+ :predicate predicate
+ :require-match require-match
+ :initial-input initial-input
+ :preselect def
+ :history history
+ :keymap nil
+ :sort t))
;;;###autoload
(define-minor-mode ivy-mode
diff --git a/swiper.el b/swiper.el
index f123c73..083c22c 100644
--- a/swiper.el
+++ b/swiper.el
@@ -186,11 +186,10 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(replace-regexp-in-string
"%s" "pattern: " swiper--format-spec)
candidates
- nil
- initial-input
- swiper-map
- preselect
- #'swiper--update-input-ivy))
+ :initial-input initial-input
+ :keymap swiper-map
+ :preselect preselect
+ :update-fn #'swiper--update-input-ivy))
(swiper--cleanup)
(if (null ivy-exit)
(goto-char swiper--opoint)
- [elpa] master 769023b 03/22: ivy.el (ivy-read): Use initial-input when completing files, (continued)
- [elpa] master 769023b 03/22: ivy.el (ivy-read): Use initial-input when completing files, Oleh Krehel, 2015/04/22
- [elpa] master 12c25a0 04/22: ivy.el (ivy-read): Don't add the `default-directory', Oleh Krehel, 2015/04/22
- [elpa] master 37d371c 05/22: Add a way to exit ignoring the candidates, Oleh Krehel, 2015/04/22
- [elpa] master 4adc074 06/22: Fix the default-directory for `counsel-git-grep', Oleh Krehel, 2015/04/22
- [elpa] master dd559ad 07/22: ivy.el (ivy--filter): Try directory expansion with "/", Oleh Krehel, 2015/04/22
- [elpa] master 6da7819 09/22: ivy.el (ivy--filter): Update prefix optimization, Oleh Krehel, 2015/04/22
- [elpa] master 533b788 11/22: ivy.el (ivy-done): Be more strict for `require-match', Oleh Krehel, 2015/04/22
- [elpa] master fb805a0 08/22: README.md: Add a note on outdated ivy package, Oleh Krehel, 2015/04/22
- [elpa] master 70c5fe8 13/22: Bind "M-q" to `ivy-toggle-regexp-quote', Oleh Krehel, 2015/04/22
- [elpa] master 7edfbc9 14/22: ivy.el (ivy--exhibit): Wrap in `while-no-input', Oleh Krehel, 2015/04/22
- [elpa] master 1fad831 10/22: Change `ivy-read' to a cl-defun,
Oleh Krehel <=
- [elpa] master e78557a 15/22: swiper.el (swiper--ivy): Fix preselect being added, Oleh Krehel, 2015/04/22
- [elpa] master 28abaa9 12/22: Allow to customize the regex matching per-collection, Oleh Krehel, 2015/04/22
- [elpa] master dd4aced 16/22: ivy.el (ivy--add-face): Don't fail for weird str, Oleh Krehel, 2015/04/22
- [elpa] master 6d801a6 19/22: ivy-test.el (ivy-read): Update test., Oleh Krehel, 2015/04/22
- [elpa] master 5c03c2b 18/22: ivy.el (ivy-read): Fix preselect logic, Oleh Krehel, 2015/04/22
- [elpa] master f9947de 20/22: Fixup `swiper-query-replace', Oleh Krehel, 2015/04/22
- [elpa] master 632af83 17/22: ivy.el (ivy-done): Fixup, Oleh Krehel, 2015/04/22
- [elpa] master e2452a3 21/22: README.md: Update video link, Oleh Krehel, 2015/04/22
- [elpa] master c7a6156 22/22: Merge commit 'e2452a3e77ef6ea6b193292d2c0bbbe93dd4b078' from swiper, Oleh Krehel, 2015/04/22