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

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

[elpa] externals/kiwix c09f7ad 041/192: optimize open link function


From: Stefan Monnier
Subject: [elpa] externals/kiwix c09f7ad 041/192: optimize open link function
Date: Sat, 19 Dec 2020 00:41:29 -0500 (EST)

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

    optimize open link function
---
 kiwix.el | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/kiwix.el b/kiwix.el
index 52b7235..c5c12be 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -73,8 +73,8 @@
                                (replace-regexp-in-string "\.zim" "" var))
                            kiwix-libraries)))
 
-(defvar kiwix-librarie-abbrev-list
-  '(("default" . "en")
+(defvar kiwix-librarie-abbrev-alist
+  '(("default" . "wikipedia_en_all_2016-02")
     ;; TODO:
     ;; (mapcar #'(lambda (var)
     ;;             (string-match-p "en" var))
@@ -86,11 +86,11 @@
 (defun kiwix-select-library-abbrev ()
   "Select Wikipedia library name abbrev."
   (completing-read "Wikipedia library abbrev: "
-                   (map-keys kiwix-librarie-abbrev-list)))
+                   (map-keys kiwix-librarie-abbrev-alist)))
 
-(defun kiwix-select-library-fullname (abbr)
+(defun kiwix-get-library-fullname (abbr)
   "Get Kiwix library full name which is associated with `ABBR'."
-  (cdr (assoc abbr kiwix-librarie-abbrev-list)))
+  (cdr (assoc abbr kiwix-librarie-abbrev-alist)))
 
 ;; launch Kiwix server
 ;;;###autoload
@@ -152,31 +152,29 @@ for query string and library interactively."
 ;; - group 2: link? (match everything but ], space, tab, carriage return, 
linefeed by using [^] \n\t\r]*)
 ;; for open wiki search query with local application database.
 
-;; TODO: deprecated
-;; (defalias 'org-wiki-link-open 'kiwix-query)
-
 (defun org-wiki-link-open (link)
   "Open LINK in external wiki program."
-  (cond ((string-match "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)"  link) ; 
(library):query
-         (let* (
-                ;; convert between libraries full name and abbrev.
-                (library (kiwix-select-library-fullname (match-string 1 link)))
-                (query (match-string 2 link))
-                (url (concat kiwix-server-url library "/A/" (url-encode-url 
(capitalize query)) ".html")))
-           ;; (prin1 (format "library: %s, query: %s" library query))
-           (browse-url url)))
-        ((string-match "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)"  link) ; query
-         (let* ((query (match-string 2 link))
-                (url (concat kiwix-server-url kiwix-default-library "/A/" 
(url-encode-url (capitalize query)) ".html")))
-           ;; (print1 (format "query: %s" query))
-           (browse-url url)))))
+  (when (string-match "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)"  link) ; 
(library):query
+    (let* (
+           ;; convert between libraries full name and abbrev.
+           (library (kiwix-get-library-fullname (or (match-string 1 link)
+                                                    "default")))
+           (query (match-string 2 link))
+           (url (concat
+                 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))
+                 ".html")))
+      ;; (prin1 (format "library: %s, query: %s, url: %s" library query url))
+      (browse-url url))
+    ))
 
 (defun org-wiki-link-export (link description format)
   "Export the wiki LINK with DESCRIPTION for FORMAT from Org files."
   (when (string-match "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)" link)
     (let* ((library (or (match-string 1 link)
-                        (kiwix-select-library-fullname "default")))
-           ;; query need to be convert to URL encoding: "禅宗" 
https://zh.wikipedia.org/wiki/%E7%A6%85%E5%AE%97
+                        (kiwix-get-library-fullname "default")))
            (query (url-encode-url (or (match-string 2 link) description)))
            ;; "http://en.wikipedia.org/wiki/Linux";
            ;;         --



reply via email to

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