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

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

[elpa] externals/kiwix f5d7a2f 180/192: support Org Mode link :complete


From: Stefan Monnier
Subject: [elpa] externals/kiwix f5d7a2f 180/192: support Org Mode link :complete property function
Date: Sat, 19 Dec 2020 00:41:56 -0500 (EST)

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

    support Org Mode link :complete property function
---
 kiwix.el     | 39 ++++++++++++++++++++-------------------
 org-kiwix.el | 12 ++++++++++--
 2 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/kiwix.el b/kiwix.el
index 80292fe..9c9c145 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -243,25 +243,26 @@ Like in function `kiwix-ajax-search-hints'.")
 (defun kiwix-ajax-search-hints (input &optional selected-library)
   "Instantly AJAX request to get available Kiwix entry keywords
 list and return a list result."
-  (let* ((library (or selected-library
-                      (kiwix--get-library-name (or kiwix--selected-library
-                                                   kiwix-default-library))))
-         (ajax-api (format "%s/suggest?content=%s&term="
-                           kiwix-server-url
-                           library))
-         (ajax-url (concat ajax-api input))
-         (data (request-response-data
-                (let ((inhibit-message t))
-                  (request ajax-url
-                           :type "GET"
-                           :sync t
-                           :headers '(("Content-Type" . "application/json"))
-                           :parser #'json-read
-                           :success (function*
-                                     (lambda (&key data &allow-other-keys)
-                                       data)))))))
-    (if (vectorp data)
-        (mapcar 'cdar data))))
+  (when input
+    (let* ((library (or selected-library
+                        (kiwix--get-library-name (or kiwix--selected-library
+                                                     kiwix-default-library))))
+           (ajax-api (format "%s/suggest?content=%s&term="
+                             kiwix-server-url
+                             library))
+           (ajax-url (concat ajax-api input))
+           (data (request-response-data
+                  (let ((inhibit-message t))
+                    (request ajax-url
+                      :type "GET"
+                      :sync t
+                      :headers '(("Content-Type" . "application/json"))
+                      :parser #'json-read
+                      :success (function*
+                                (lambda (&key data &allow-other-keys)
+                                  data)))))))
+      (if (vectorp data)
+          (mapcar 'cdar data)))))
 
 ;;;###autoload
 (defun kiwix-at-point (&optional interactively)
diff --git a/org-kiwix.el b/org-kiwix.el
index 0516c72..6ccc672 100644
--- a/org-kiwix.el
+++ b/org-kiwix.el
@@ -1,6 +1,6 @@
 ;;; org-kiwix.el --- Org Mode link support -*- lexical-binding: t; -*-
 
-;;; Time-stamp: <2020-04-28 10:06:10 stardiviner>
+;;; Time-stamp: <2020-04-28 10:38:02 stardiviner>
 
 ;;; Commentary:
 
@@ -102,11 +102,19 @@
                             :description query)
       link)))
 
+(defun org-wikipedia-complete-link (&optional arg)
+  "Use kiwix AJAX request to provide available completion keywords."
+  (let* ((input (or arg (read-from-minibuffer "Search keyword: ")))
+         (keywords (kiwix-ajax-search-hints input)))
+    (concat "wikipedia:"
+            (completing-read "Available keywords: " keywords))))
+
 ;;;###autoload
 (org-link-set-parameters "wikipedia" ; NOTE: use `wikipedia' for future 
backend changing.
                          :follow #'org-wikipedia-open-link
                          :store #'org-wikipedia-store-link
-                         :export #'org-wikipedia-export-link)
+                         :export #'org-wikipedia-export-link
+                         :complete #'org-wikipedia-complete-link)
 
 ;;;###autoload
 (add-hook 'org-store-link-functions 'org-wikipedia-store-link t)



reply via email to

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