emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]