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

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

[elpa] externals/kiwix fb83985 062/192: Merge branch 'master' into devel


From: Stefan Monnier
Subject: [elpa] externals/kiwix fb83985 062/192: Merge branch 'master' into develop
Date: Sat, 19 Dec 2020 00:41:34 -0500 (EST)

branch: externals/kiwix
commit fb83985cd982627535027ff73b4f281e3d6e0106
Merge: 2e2d64d 634b5ae
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>

    Merge branch 'master' into develop
---
 kiwix-at-point.el | 106 ------------------------------------------------------
 kiwix-http.el     |  94 ------------------------------------------------
 kiwix.el          |  15 +++++---
 3 files changed, 11 insertions(+), 204 deletions(-)

diff --git a/kiwix-at-point.el b/kiwix-at-point.el
deleted file mode 100644
index 5cedef1..0000000
--- a/kiwix-at-point.el
+++ /dev/null
@@ -1,106 +0,0 @@
-;;; kiwix-at-point.el --- Kiwix client for Emacs
-;;; -*- coding: utf-8 -*-
-
-;;; Commentary:
-
-
-
-;;; Code:
-
-(require 'cl-lib)
-
-(defgroup kiwix-at-point nil
-  "Search in Kiwix for text at point."
-  :group 'external)
-
-(defcustom kiwix-at-point-library-alist
-  ;; e.g. 
"~/.www.kiwix.org/kiwix/8ip89lik.default/data/index/wikinews_en_all_2015-11.zim.idx"
-  '((wikipedia . "")
-    (wiktionary . "")
-    (wikinews . "")
-    (wikibooks . "")
-    (wikiquote . "")
-    (wikisource . "")
-    (wikiversity . "")
-    (wikimed . "") ; "WikiMed Medical Encyclopedia" "Wikispecies"
-    )
-  "Alist which contains available kiwix libraries."
-  :type '(repeat 'string)
-  :group 'kiwix-at-point)
-
-(defvar kiwix-at-point-library nil
-  "Variable used to specify the library for the current search.")
-(make-variable-buffer-local 'kiwix-at-point-library)
-
-(defvar kiwix-at-point--library-history nil)
-
-(defun kiwix-at-point-get-library ()
-  "Guess which library suit to the current search."
-  (or kiwix-at-point-library
-      kiwix-at-point--library-history))
-
-(defun kiwix-at-point-maybe-specify-library (search-string)
-  "Prefix SEARCH-STRING with the guessed library, if any."
-  (let ((library (kiwix-at-point-get-library)))
-    (concat (when library
-              (concat library ":"))
-            search-string)))
-
-(defun kiwix-at-point-get-idx ()
-  "Get the idx file path."
-  ;; TODO:
-  )
-
-(defun kiwix-at-point-run-search (search)
-  (if (executable-find "kiwix")
-      ;; TODO:
-      (start-process "Kiwix" nil "kiwix-search" (kiwix-at-point-get-idx) 
search)
-    (message "Kiwix wasn't found, install it first http://www.kiwix.org";)))
-
-;;;###autoload
-(defun kiwix-at-point (&optional edit-search)
-  "Search for the word at point in Kiwix."
-  (interactive "P")
-  (let* ((thing (if mark-active
-                    (buffer-substring (region-beginning) (region-end))
-                  (thing-at-point 'symbol)))
-         (search (kiwix-at-point-maybe-specify-library thing)))
-    (kiwix-at-point-run-search
-     (if (or edit-search (null thing))
-         (read-string "Kiwix search: " search)
-       search))))
-
-(defun kiwix-at-point--library-candidates ()
-  kiwix-at-point-library-alist)
-
-(defun kiwix-at-point--set-library-prompt ()
-  (let ((default-library (kiwix-at-point-get-library)))
-    (format "Kiwix library%s: "
-            (if default-library
-                (format "[Default: %s]" default-library)
-              ""))))
-
-;;;###autoload
-(defun kiwix-at-point-set-library ()
-  "Set current search's library."
-  (interactive)
-  (let ((minibuffer-local-completion-map
-         (copy-keymap minibuffer-local-completion-map)))
-    (define-key minibuffer-local-completion-map (kbd "SPC") nil)
-    (setq-local kiwix-at-point-library
-                (completing-read (kiwix-at-point--set-library-prompt)
-                                 (kiwix-at-point--library-candidates) nil nil 
nil
-                                 'kiwix-at-point--library-history 
(kiwix-at-point-get-library)))))
-
-;;;###autoload
-(defun kiwix-at-point-search (&optional edit-search)
-  "Prompt and search in Kiwix."
-  (interactive "P")
-  (let ((search (kiwix-at-point-maybe-specify-library "")))
-    (kiwix-at-point-run-search
-     (read-string "Kiwix search: " search))))
-
-
-(provide 'kiwix-at-point)
-
-;;; kiwix-at-point.el ends here
diff --git a/kiwix-http.el b/kiwix-http.el
deleted file mode 100644
index fae7b13..0000000
--- a/kiwix-http.el
+++ /dev/null
@@ -1,94 +0,0 @@
-;;; kiwix-http.el
-;;; -*- coding: utf-8 -*-
-
-;;; Commentary:
-
-
-
-;;; Code:
-
-
-(require 'cl-lib)
-
-;; FIXME:
-;; should use a standard where function to find path.
-;; you may can define a function instead or a constant holding the relative 
path, then make use of it when needed.
-(defcustom kiwix-search-command "/usr/lib/kiwix/bin/kiwix-search"
-  "The kiwix-search command path."
-  :type 'string
-  :group 'kiwix
-  :safe 'stringp)
-(defcustom kiwix-data-profile-path "~/.www.kiwix.org/kiwix/8ip89lik.default/"
-  "The kiwix profile data directory."
-  :type 'string
-  :group 'kiwix
-  :safe 'stringp)
-
-;; TODO: replace `browse-url'
-(defcustom kiwix-browser-function 'browse-url-conkeror
-  "Specify browser function to open kiwix search result."
-  :type 'function
-  :group 'kiwix
-  :safe 'functionp)
-
-(defvar kiwix-data-index-path nil)
-
-(setq kiwix-data-index-path (concat kiwix-data-profile-path "data/index/"))
-
-(defun kiwix-serve-index ()
-  "Open kiwix HTTP server index page."
-  (interactive)
-  (browse-url "http://127.0.0.1:8000";)
-  )
-
-(defun kiwix-libraries ()
-  "Get a list of dirs under a specific dir."
-  ;; ~/.www.kiwix.org/kiwix/8ip89lik.default/data/content/*.zim
-  (let ((libraries
-         ;; TODO: use a filter function from cl-lib or dash to replace 
`mapcar'.
-         (mapcar #'(lambda (file)
-                     (let ((zim-file (string-match-p ".*\\.zim\\'" file)))
-                       zim-file))
-                 (directory-files kiwix-data-index-path)
-                 )))
-    libraries))
-
-(defun kiwix-serve-search (library query)
-  "Execute shell command `kiwix-search' on `LIBRARY' with `QUERY'.
-Return a list of results."
-
-  ;; TODO: don't use shell-command.
-  ;; use execute a process sync/async. check out in Elisp info.
-  (let ((search-results (shell-command
-                         (concat kiwix-search-command " "
-                                 kiwix-data-profile-path kiwix-data-index-path
-                                 library " " query
-                                 " 2> /dev/null"))))
-    search-results)
-  )
-
-(defun kiwix-serve-query (library)
-  "Query kiwix HTTP server in a specific `LIBRARY'."
-  (interactive ; FIXME: Don't know where is wrong yet.
-   (list (completing-read
-          "Kiwix Library: "
-          (let (libraries)
-            (dolist (elt (kiwix-libraries))
-              (setq libraries (append libraries (list (car elt)))))
-            libraries))))
-  
-  (let ((query (read-from-minibuffer "Kiwix Query: "))
-        (results (kiwix-search library query))
-        (result (interactive
-                 (list (completing-read
-                        "select a result to visit: "
-                        results)))))
-    (browse-url
-     (concat "http://127.0.0.1:8000/"; library "/A/" result))
-    )
-  )
-
-
-(provide 'kiwix-http)
-
-;;; kiwix-http.el ends here
diff --git a/kiwix.el b/kiwix.el
index bac104a..3865f96 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -164,7 +164,12 @@
   (let* ((kiwix-library (if library
                             library
                           (kiwix-get-library-fullname "default")))
-         (url (concat kiwix-server-url kiwix-library "/A/" (url-encode-url 
(capitalize query)) ".html")))
+         (url (concat kiwix-server-url kiwix-library "/A/"
+                      ;; query need to be convert to URL encoding: "禅宗" 
https://zh.wikipedia.org/wiki/%E7%A6%85%E5%AE%97
+                      (url-encode-url
+                       ;; convert space to underline: "Beta distribution" 
"Beta_distribution"
+                       (replace-regexp-in-string " " "_" (capitalize query) 
nil nil))
+                      ".html")))
     (browse-url url)))
 
 ;;;###autoload
@@ -234,11 +239,13 @@ for query string and library interactively."
                  kiwix-server-url
                  library "/A/"
                  ;; query need to be convert to URL encoding: "禅宗" 
https://zh.wikipedia.org/wiki/%E7%A6%85%E5%AE%97
-                 (url-encode-url (capitalize query))
+                 (url-encode-url
+                  ;; convert space to underline: "Beta distribution" 
"Beta_distribution"
+                  (replace-regexp-in-string " " "_"
+                                            (capitalize query) nil nil))
                  ".html")))
       ;; (prin1 (format "library: %s, query: %s, url: %s" library query url))
-      (browse-url url))
-    ))
+      (browse-url url))))
 
 (defun org-wiki-link-export (link description format)
   "Export the wiki LINK with DESCRIPTION for FORMAT from Org files."



reply via email to

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