branch: externals/kiwix commit 8d5e53cdf6163961e3c99f9aed23ffb4fd64e1bf Author: stardiviner <numbch...@gmail.com> Commit: stardiviner <numbch...@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)