branch: externals/kiwix
commit aa4ac221279c792c1ef98cb88a0e259522a7647d
Author: stardiviner <[email protected]>
Commit: stardiviner <[email protected]>
improve interactive function
---
kiwix.el | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/kiwix.el b/kiwix.el
index e138aa6..6167158 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -34,11 +34,16 @@
:type 'string
:group 'kiwix)
-(defcustom kiwix-default-data-path "8ip89lik.default"
+(defcustom kiwix-default-data-profile-name "8ip89lik.default"
"Specify the default Kiwix data profile path."
:type 'string
:group 'kiwix)
+(defcustom kiwix-default-data-path (shell-quote-argument (concat (getenv
"HOME") "/.www.kiwix.org/kiwix/" kiwix-default-data-profile-name))
+ "Specify the default Kiwix data path."
+ :type 'string
+ :group 'kiwix)
+
(defcustom kiwix-default-library "wikipedia_en_all_2016-02"
"Specify the default Kiwix library you want to search."
:type 'string
@@ -59,6 +64,9 @@
:type 'boolean
:group 'kiwix)
+(defvar kiwix-libraries (directory-files (concat kiwix-default-data-path
"/data/content/") nil "\.zim")
+ "A list of Kiwix libraries.")
+
;; launch Kiwix server
;;;###autoload
(defun kiwix-launch-server ()
@@ -68,7 +76,7 @@
(let ((library "--library ")
(port (concat "--port=" kiwix-server-port " "))
(daemon "--daemon ")
- (library-path (shell-quote-argument (concat (getenv "HOME")
"/.www.kiwix.org/kiwix/" kiwix-default-data-path "/data/library/library.xml")))
+ (library-path (concat kiwix-default-data-path
"/data/library/library.xml"))
)
(async-shell-command
(concat kiwix-server-command library port daemon library-path))))
@@ -83,15 +91,24 @@
(browse-url url)))
;;;###autoload
-(defun kiwix-at-point (&optional input)
- "Search for the symbol at point with `kiwix-query' with `INPUT'."
+(defun kiwix-at-point (&optional interactively)
+ "Search for the symbol at point with `kiwix-query'.
+
+Or When prefix argument `INTERACTIVELY' specified, then prompt
+for query string and library interactively."
(interactive "P")
- (let* ((query-string (if mark-active
- (buffer-substring (region-beginning) (region-end))
- (thing-at-point 'symbol))))
- (kiwix-query (if (or input (null query-string))
- (read-string "Kiwix search: " query-string-input)
- query-string))))
+ (let* ((query-string (if interactively
+ (read-string "Kiwix Search: "
+ (if mark-active
+ (buffer-substring
+ (region-beginning) (region-end))
+ (thing-at-point 'symbol)))))
+ (library (when interactively
+ (completing-read "Kiwix Library: "
+ (mapcar #'(lambda (var)
+ (replace-regexp-in-string
"\.zim" "" var))
+ kiwix-libraries)))))
+ (kiwix-query query-string library)))
;;; Support Org-mode
;; [[wiki:]]