[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kiwix b84a5ff 047/192: Merge branch 'release/v0.4.0'
From: |
Stefan Monnier |
Subject: |
[elpa] externals/kiwix b84a5ff 047/192: Merge branch 'release/v0.4.0' |
Date: |
Sat, 19 Dec 2020 00:41:30 -0500 (EST) |
branch: externals/kiwix
commit b84a5ff33efdf13dda22ed32ea37a09b15cd1690
Merge: c5df1ac 90ac73a
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>
Merge branch 'release/v0.4.0'
---
README.org | 21 ++++++++++-
kiwix.el | 122 ++++++++++++++++++++++++++++++++++++++++---------------------
2 files changed, 101 insertions(+), 42 deletions(-)
diff --git a/README.org b/README.org
index 858fafa..68f20ae 100644
--- a/README.org
+++ b/README.org
@@ -48,7 +48,7 @@ Here is a simple script, you can put it in Linux
"*auto-start*".
http://127.0.0.1:8000/wikinews_en_all_2015-11/A/Big_Linux_Beta_3_released.html
#+BEGIN_SRC emacs-lisp
- (browse-url (concat "http://127.0.0.1:8000/" "LIBRARY" "A" "RESULT"))
+ (browse-url (concat "http://127.0.0.1:8000/" "LIBRARY" "/A/" "RESULT"))
#+END_SRC
@@ -59,3 +59,22 @@ with RESTful API.
- I don't know what Emacs library to use.
- Or you can use other language to do this, like Ruby or Python etc.
+
+
+* Usage
+
+** Use in Emacs
+
+=[M-x kiwix-at-point]=
+
+** Org-mode integration
+
+=[C-c C-l]= to insert link.
+
+The link format is like this:
+
+#+BEGIN_EXAMPLE
+[[wiki:(library):search][description]]
+#+END_EXAMPLE
+
+The =(library)= can be =wikipedia_en=, =wikipedia_zh=, =wiktionary_en= etc.
diff --git a/kiwix.el b/kiwix.el
index c5c12be..d302aac 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -7,7 +7,7 @@
;; URL: https://github.com/stardiviner/kiwix.el
;; Created: 23th July 2016
;; Version: 0.1.0
-;; Package-Requires: ((emacs "24.3"))
+;; Package-Requires: ((emacs "24.3") (cl-lib "2.0"))
;;; Commentary:
@@ -25,6 +25,8 @@
;;; Code:
+(require 'cl-lib)
+
(defgroup kiwix nil
"Kiwix customization options.")
@@ -33,26 +35,36 @@
:type 'string
:group 'kiwix)
-(defcustom kiwix-server-command "/usr/lib/kiwix/bin/kiwix-serve "
+(defcustom kiwix-server-command
+ (cond
+ ((string-equal system-type "gnu/linux")
+ "/usr/lib/kiwix/bin/kiwix-serve ")
+ ((string-equal system-type "darwin")
+ (warn "You need to specify Mac OS X Kiwix path. And send a PR to my
repo."))
+ ((string-equal system-type "windows-nt")
+ (warn "You need to specify Windows Kiwix path. And send a PR to my
repo.")))
"Specify kiwix server command."
:type 'string
:group 'kiwix)
-(defcustom kiwix-default-data-profile-name "8ip89lik.default"
+(defcustom kiwix-default-data-profile-name
+ (car (directory-files
+ (concat
+ (getenv "HOME") "/.www.kiwix.org/kiwix")
+ nil
+ ".*\\.default"
+ ))
"Specify the default Kiwix data profile path."
:type 'string
:group 'kiwix)
-(defcustom kiwix-default-data-path (concat (getenv "HOME")
"/.www.kiwix.org/kiwix/" kiwix-default-data-profile-name)
+(defcustom kiwix-default-data-path
+ (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
- :group 'kiwix)
-
(defcustom kiwix-server-port "8000"
"Specify the default Kiwix server port."
:type 'string
@@ -63,34 +75,55 @@
:type 'boolean
:group 'kiwix)
-(defvar kiwix-libraries (directory-files (concat kiwix-default-data-path
"/data/content/") nil "wikipedia_.*_all_.*\.zim")
+(defvar kiwix-libraries
+ (mapcar #'(lambda (var)
+ (replace-regexp-in-string "\.zim" "" var))
+ (directory-files
+ (concat kiwix-default-data-path "/data/content/") nil ".*\.zim"))
"A list of Kiwix libraries.")
-(defun kiwix-select-library ()
- "Select Wikipedia library full name."
- (completing-read "Kiwix Library: "
- (mapcar #'(lambda (var)
- (replace-regexp-in-string "\.zim" "" var))
- kiwix-libraries)))
-
-(defvar kiwix-librarie-abbrev-alist
- '(("default" . "wikipedia_en_all_2016-02")
- ;; TODO:
- ;; (mapcar #'(lambda (var)
- ;; (string-match-p "en" var))
- ;; kiwix-libraries)
- ("en" . "wikipedia_en_all_2016-02")
- ("zh" . "wikipedia_zh_all_2015-11")
- ))
-
-(defun kiwix-select-library-abbrev ()
+;; - examples:
+;; - "wikipedia_en" - "wikipedia_en_all_2016-02"
+;; - "wikipedia_zh" - "wikipedia_zh_all_2015-17"
+;; - "wiktionary_en" - "wiktionary_en_all_2015-17"
+;; - "wiktionary_zh" - "wiktionary_zh_all_2015-17"
+
+(defun kiwix-construct-libraries-abbrev-alist (alist)
+ "Construct libraries abbrev alist from `ALIST'."
+ (let* ((libraries-name
+ (mapcar #'(lambda (library)
+ (string-match "\\(.*\\)_all_.*" library)
+ (let* ((library-name (match-string 1 library)))
+ library-name))
+ alist))
+ (libraries-full-name alist))
+ (cl-pairlis libraries-name libraries-full-name)))
+
+(defvar kiwix-libraries-abbrev-alist
+ (kiwix-construct-libraries-abbrev-alist kiwix-libraries)
+ "Alist of Kiwix libraries with name and full name.")
+
+(defcustom kiwix-default-library "wikipedia_en"
+ "The default kiwix library when library fragment in link not specified.")
+
+;; add default key-value pair to libraries alist.
+(defvar kiwix-default-library-cons
+ (cons "default" (kiwix-get-library-fullname kiwix-default-library)))
+
+;; add `kiwix-default-library-cons' to alist.
+(push kiwix-default-library-cons kiwix-libraries-abbrev-alist)
+;; test
+;; (kiwix-get-library-fullname "wikipedia_en")
+;; (kiwix-get-library-fullname "default")
+
+(defun kiwix-select-library-name ()
"Select Wikipedia library name abbrev."
(completing-read "Wikipedia library abbrev: "
- (map-keys kiwix-librarie-abbrev-alist)))
+ (map-keys kiwix-libraries-abbrev-alist)))
(defun kiwix-get-library-fullname (abbr)
"Get Kiwix library full name which is associated with `ABBR'."
- (cdr (assoc abbr kiwix-librarie-abbrev-alist)))
+ (cdr (assoc abbr kiwix-libraries-abbrev-alist)))
;; launch Kiwix server
;;;###autoload
@@ -111,7 +144,7 @@
"Search `QUERY' in `LIBRARY' with Kiwix."
(let* ((kiwix-library (if library
library
- kiwix-default-library))
+ (kiwix-get-library-fullname "default")))
(url (concat kiwix-server-url kiwix-library "/A/" (url-encode-url
(capitalize query)) ".html")))
(browse-url url)))
@@ -122,15 +155,22 @@
Or When prefix argument `INTERACTIVELY' specified, then prompt
for query string and library interactively."
(interactive "P")
- (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
- (kiwix-select-library))))
- (kiwix-query query-string library)))
+ (let* ((library (if interactively
+ (kiwix-get-library-fullname (kiwix-select-library-name))
+ (kiwix-get-library-fullname "default")))
+ (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))))))
+ (message (format "library: %s, query: %s" library query))
+ (kiwix-query query library)))
@@ -194,7 +234,7 @@ for query string and library interactively."
;; remove those interactive functions. use normal function instead.
(when (eq major-mode 'wiki-mode)
(let* ((query (read-string "Wiki Query: "))
- (library (kiwix-select-library-abbrev))
+ (library (kiwix-select-library-name))
(link (concat "wiki:" "(" library "):" query)))
(org-store-link-props
:type "wiki"
- [elpa] externals/kiwix aa4ac22 023/192: improve interactive function, (continued)
- [elpa] externals/kiwix aa4ac22 023/192: improve interactive function, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d684140 024/192: Quote path argument each time it's used, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f43e006 028/192: add Kiwix installation commentary, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix e527614 032/192: Merge branch 'release/v0.2.1', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 00c5a17 033/192: Merge tag 'v0.2.1' into develop, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 164cf9c 034/192: disable Wikipedia_Local link abbrev, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix c3e2d85 038/192: fix query is chinese string issue, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix c5df1ac 042/192: Merge branch 'release/v0.3.0', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix fb92b4f 043/192: Merge tag 'v0.3.0' into develop, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 1ddddc1 044/192: improve library fragment, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix b84a5ff 047/192: Merge branch 'release/v0.4.0',
Stefan Monnier <=
- [elpa] externals/kiwix 19bfe4f 051/192: add an option to let kiwix-at-point search interactively, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d4fbf7b 052/192: define function ahead, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f1554ba 054/192: fix some default library abbr name., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 4968e3d 055/192: error when query is invalid., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 1b9f25b 056/192: add interactively called function., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 2e2d64d 059/192: Merge tag 'v0.4.3' into develop, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 8855ac4 060/192: delete deprecated source code files., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix fb83985 062/192: Merge branch 'master' into develop, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 45cc8ef 067/192: add some links test., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d9bab20 074/192: Merge branch 'release/v0.5.1', Stefan Monnier, 2020/12/19