[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kiwix 6c6c443 176/192: fix Org link open function
From: |
Stefan Monnier |
Subject: |
[elpa] externals/kiwix 6c6c443 176/192: fix Org link open function |
Date: |
Sat, 19 Dec 2020 00:41:55 -0500 (EST) |
branch: externals/kiwix
commit 6c6c44386e00d352d96064cb25b50e960cd1ba22
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>
fix Org link open function
- support detect chinese query
- support wikipedia: link spec "(library):query"
---
kiwix.el | 52 ++++++++++++++++++++++++++++++----------------------
1 file changed, 30 insertions(+), 22 deletions(-)
diff --git a/kiwix.el b/kiwix.el
index c5da69b..a67aacf 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -347,34 +347,42 @@ for query string and library interactively."
(defun kiwix-org-get-library (link)
"Get library from Org-mode `LINK'."
- (if (string-match-p "[a-zA-Z\ ]+" (match-string 2 link)) ; validate query is
English
- ;; convert between libraries full name and abbrev.
- (or (match-string 1 link) (kiwix-select-library "en"))
- ;; validate query is non-English
- (kiwix-select-library "zh")))
+ (cond
+ ((chinese-string-p link)
+ (kiwix-select-library "zh"))
+ ((string-match-p "[a-zA-Z\ ]+" link)
+ ;; convert between libraries full name and abbrev.
+ (kiwix-select-library "en"))
+ (t (kiwix-select-library))))
;;;###autoload
(defun org-wikipedia-link-open (link)
"Open LINK in external Wikipedia program."
;; The regexp: (library):query
;; - query : should not exclude space
- (when (string-match "\\(?:(\\(.*\\)):\\)?\\([^]\n\t\r]*\\)" link) ;
(library):query
- (let* ((library (kiwix-org-get-library link))
- (query (if (chinese-string-p link) link (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
- ;; convert space to underline: "Beta distribution"
"Beta_distribution"
- (replace-regexp-in-string
- " " "_"
- ;; only capitalize the first word. like: "meta-circular
interpreter" -> "Meta-circular interpreter"
- (kiwix-capitalize-first query)
- nil nil))
- ".html")))
- ;; (prin1 (format "library: %s, query: %s, url: %s" library query url))
- (browse-url url))))
+ ;; match link spec: "(library):query" with regexp "([^).]*):?:.*"
+ ;; (string-match "\\(?:(\\(.*\\)):\\)?\\([^]\n\t\r]*\\)" link)
+ (string-match "(\\([^)].*\\)):\\(.*\\)" link)
+ (let* ((library (kiwix-org-get-library link))
+ (query (cond
+ ((chinese-string-p link) link)
+ ((string-match-p "(\\([^)].*\\)):\\(.*\\)" link)
+ (match-string 2 link))
+ (t 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
+ ;; convert space to underline: "Beta distribution"
"Beta_distribution"
+ (replace-regexp-in-string
+ " " "_"
+ ;; only capitalize the first word. like: "meta-circular
interpreter" -> "Meta-circular interpreter"
+ (kiwix-capitalize-first query)
+ nil nil))
+ ".html")))
+ ;; (prin1 (format "library: %s, query: %s, url: %s" library query url))
+ (browse-url url)))
;;;###autoload
(defun org-wikipedia-link-export (link description format)
- [elpa] externals/kiwix 4243689 156/192: check whether Docker image "kiwix/kiwix-serve" is available, (continued)
- [elpa] externals/kiwix 4243689 156/192: check whether Docker image "kiwix/kiwix-serve" is available, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d7c4778 162/192: select library require matched in candidates, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 5b5b117 163/192: improve the kiwix-query URL to use the search API, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f4a1e2d 164/192: rename function* -> cl-function, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix cf6fc32 165/192: add :status-code handler, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 3fe879f 168/192: refresh libraries before selecting library, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 716c5f6 169/192: Docker container launch command use library.xml index file, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix cd95bc9 171/192: update README: using libraries index file "library.xml", Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 9db0a13 172/192: display screenshots at beginning, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 5f64044 175/192: support detect whether query is chinese, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 6c6c443 176/192: fix Org link open function,
Stefan Monnier <=
- [elpa] externals/kiwix 7fda411 184/192: fix org-link-set-parameters functions not available when Org not loaded, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 5bd84a6 187/192: select kiwix library when completing org link, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d92a371 189/192: Fix some byte-compile warnings, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 905a413 192/192: Fix #4 add GNU license info in package source code file, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 2d33910 072/192: Merge tag 'v0.5.0' into develop, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix bf128fb 087/192: Merge branch 'hotfix/void-function_org-link-set-parameters', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f3a2d8f 091/192: Merge branch 'release/0.6.1', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f84b449 070/192: autoload Org-mode link adding, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 3485131 071/192: Merge branch 'develop', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 21b5dfe 073/192: fix variable invalid for autoload kiwix, Stefan Monnier, 2020/12/19