[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 881cbc5 130/184: counsel.el (counsel-google-function): Use
From: |
Oleh Krehel |
Subject: |
[elpa] master 881cbc5 130/184: counsel.el (counsel-google-function): Use request in async mode |
Date: |
Wed, 16 Oct 2019 13:15:05 -0400 (EDT) |
branch: master
commit 881cbc516a7355226731f6772b5284fd12c55c1c
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-google-function): Use request in async mode
Re #2263
---
counsel.el | 29 +++++++++++++++++------------
ivy.el | 19 ++++++++++++++-----
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/counsel.el b/counsel.el
index 927428c..64c6168 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5921,22 +5921,27 @@ Additional actions:\\<ivy-minibuffer-map>
;;* `counsel-google'
(defun counsel-google-function (input)
+ "Create a request to Google with INPUT.
+Return 0 tells `ivy--exhibit' not to update the minibuffer.
+We update it in the callback with `ivy-update-candidates'."
(or
(ivy-more-chars)
- (mapcar #'identity
- (aref
- (request-response-data
- (request
- "http://suggestqueries.google.com/complete/search"
- :type "GET"
- :params (list
- (cons "client" "firefox")
- (cons "q" input))
- :parser 'json-read
- :sync t))
- 1))))
+ (progn
+ (request
+ "http://suggestqueries.google.com/complete/search"
+ :type "GET"
+ :params (list
+ (cons "client" "firefox")
+ (cons "q" input))
+ :parser 'json-read
+ :success (cl-function
+ (lambda (&key data &allow-other-keys)
+ (ivy-update-candidates
+ (mapcar #'identity (aref data 1))))))
+ 0)))
(defun counsel-google ()
+ "Ivy interface for Google."
(interactive)
(ivy-read "search: " #'counsel-google-function
:action (lambda (x)
diff --git a/ivy.el b/ivy.el
index fc1df4c..14b1002 100644
--- a/ivy.el
+++ b/ivy.el
@@ -3107,6 +3107,11 @@ Should be run via minibuffer `post-command-hook'."
(concat remote "~/")
"~/"))))
+(defun ivy-update-candidates (cands)
+ (ivy--insert-minibuffer
+ (ivy--format
+ (setq ivy--all-candidates cands))))
+
(defun ivy--exhibit ()
"Insert Ivy completions display.
Should be run via minibuffer `post-command-hook'."
@@ -3117,15 +3122,19 @@ Should be run via minibuffer `post-command-hook'."
(if (ivy-state-dynamic-collection ivy-last)
;; while-no-input would cause annoying
;; "Waiting for process to die...done" message interruptions
- (let ((inhibit-message t))
+ (let ((inhibit-message t)
+ coll in-progress)
(unless (equal ivy--old-text ivy-text)
(while-no-input
- (setq ivy--all-candidates
- (ivy--sort-maybe
- (funcall (ivy-state-collection ivy-last) ivy-text)))
+ (setq coll (funcall (ivy-state-collection ivy-last) ivy-text))
+ (when (eq coll 0)
+ (setq coll nil)
+ (setq in-progress t))
+ (setq ivy--all-candidates (ivy--sort-maybe coll))
(setq ivy--old-text ivy-text)))
(when (or ivy--all-candidates
- (not (get-process " *counsel*")))
+ (and (not (get-process " *counsel*"))
+ (not in-progress)))
(ivy--set-index-dynamic-collection)
(ivy--insert-minibuffer
(ivy--format ivy--all-candidates))))
- [elpa] master 47f6427 105/184: counsel.el (counsel-compile): favour project root over default-directory, (continued)
- [elpa] master 47f6427 105/184: counsel.el (counsel-compile): favour project root over default-directory, Oleh Krehel, 2019/10/16
- [elpa] master 09507fc 109/184: counsel.el (counsel-mark-ring): Fix highlight line of selected candidate, Oleh Krehel, 2019/10/16
- [elpa] master 46db1b9 107/184: counsel.el (counsel-mark-ring): Add customize variable to sort or not, Oleh Krehel, 2019/10/16
- [elpa] master c0aa563 112/184: ivy.el (ivy-occur): Set up next-error-function, Oleh Krehel, 2019/10/16
- [elpa] master 1a74a21 110/184: ivy-occur: setup for next-error., Oleh Krehel, 2019/10/16
- [elpa] master 30adc93 115/184: Add actions to counsel-switch-buffer, Oleh Krehel, 2019/10/16
- [elpa] master 892e44a 079/184: doc: Add full text of licences, Oleh Krehel, 2019/10/16
- [elpa] master 4645e89 121/184: swiper.el (swiper-action-copy): Add and bind to "M-o w", Oleh Krehel, 2019/10/16
- [elpa] master 77997ea 120/184: counsel.el (counsel-M-x-transformer): Handle read-only strings, Oleh Krehel, 2019/10/16
- [elpa] master 1984068 122/184: doc/ivy.org: Update GFDL license to no Invariant Sections, Oleh Krehel, 2019/10/16
- [elpa] master 881cbc5 130/184: counsel.el (counsel-google-function): Use request in async mode,
Oleh Krehel <=
- [elpa] master b39f383 125/184: counsel.el (counsel-git-grep-occur): Re-use counsel-grep-like-occur, Oleh Krehel, 2019/10/16
- [elpa] master c9f1889 136/184: swiper.el (swiper--query-replace-setup): Fix "^$" issue, Oleh Krehel, 2019/10/16
- [elpa] master b9bb7c6 140/184: ivy.el (ivy-configure): New function to configure many things at once, Oleh Krehel, 2019/10/16
- [elpa] master e3dabec 143/184: counsel.el: Use ivy-configure :unwind-fn, Oleh Krehel, 2019/10/16
- [elpa] master f16ac0e 148/184: ivy.el (ivy--format): Set case-fold-search, Oleh Krehel, 2019/10/16
- [elpa] master 501ac71 151/184: ivy.el (ivy-occur-revert-buffer): Re-use ivy-highlight-grep-commands, Oleh Krehel, 2019/10/16
- [elpa] master 6b0c41b 167/184: ivy.el (ivy-sort-file-function-using-ido): Make obsolete, Oleh Krehel, 2019/10/16
- [elpa] master 22cc602 160/184: counsel.el (counsel-find-symbol): Should not show up in counsel-M-x, Oleh Krehel, 2019/10/16
- [elpa] master b85f857 166/184: .github/FUNDING.yml: Add github, Oleh Krehel, 2019/10/16
- [elpa] master 722250c 162/184: counsel.el (counsel-imenu-action): Handle nil case, Oleh Krehel, 2019/10/16