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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/kiwix 8d5e53c 138/192: add query string related wikiped


From: Stefan Monnier
Subject: [elpa] externals/kiwix 8d5e53c 138/192: add query string related wikipedia entries through kiwix AJAX instantly search
Date: Sat, 19 Dec 2020 00:41:48 -0500 (EST)

branch: externals/kiwix
commit 8d5e53cdf6163961e3c99f9aed23ffb4fd64e1bf
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>

    add query string related wikipedia entries through kiwix AJAX instantly 
search
---
 kiwix.el | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/kiwix.el b/kiwix.el
index 22552e9..fb4c5ae 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -191,6 +191,23 @@
            :error (function* (lambda (&rest args &key error-thrown 
&allow-other-keys)
                                (setq kiwix-server-available? nil)))))
 
+(defun kiwix-ajax-search-hints (input)
+  "Instantly AJAX request to get available Kiwix entry keywords
+list and return a list result."
+  (let* ((ajax-api 
"http://127.0.0.1:8089/suggest?content=wikipedia_zh_all_2015-11&term=";)
+         (ajax-url (concat ajax-api input))
+         (data (request-response-data
+                (request ajax-url
+                         :type "GET"
+                         :sync t
+                         :headers '(("Content-Type" . "application/json"))
+                         :parser #'json-read
+                         :success (function*
+                                   (lambda (&key data &allow-other-keys)
+                                     (print data)))))))
+    (if (vectorp data)
+        (mapcar 'cdar data))))
+
 ;;;###autoload
 (defun kiwix-at-point (&optional interactively)
   "Search for the symbol at point with `kiwix-query'.
@@ -203,14 +220,17 @@ for query string and library interactively."
       (let* ((library (if (or kiwix-search-interactively interactively)
                           (kiwix-select-library)
                         (kiwix--get-library-name kiwix-default-library)))
-             (query (if interactively
-                        (read-string "Kiwix Search: "
-                                     (if mark-active
-                                         (buffer-substring (region-beginning) 
(region-end))
-                                       (thing-at-point 'symbol)))
-                      (progn (if mark-active
-                                 (buffer-substring (region-beginning) 
(region-end))
-                               (thing-at-point 'symbol))))))
+             (query (completing-read
+                     "Kiwix related entries: "
+                     (kiwix-ajax-search-hints
+                      (if interactively
+                          (read-string "Kiwix Search: "
+                                       (if mark-active
+                                           (buffer-substring 
(region-beginning) (region-end))
+                                         (thing-at-point 'symbol)))
+                        (progn (if mark-active
+                                   (buffer-substring (region-beginning) 
(region-end))
+                                 (thing-at-point 'symbol))))))))
         (message (format "library: %s, query: %s" library query))
         (if (or (null library)
                 (string-empty-p library)



reply via email to

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