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

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

[elpa] externals/kiwix 5f64044 175/192: support detect whether query is


From: Stefan Monnier
Subject: [elpa] externals/kiwix 5f64044 175/192: support detect whether query is chinese
Date: Sat, 19 Dec 2020 00:41:55 -0500 (EST)

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

    support detect whether query is chinese
---
 kiwix.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kiwix.el b/kiwix.el
index 4794e78..c5da69b 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -339,11 +339,17 @@ 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.
 
+(defun chinese-string-p (string)
+  "Return t if STRING is a Chinese string."
+  (if (string-match (format "\\cC\\{%s\\}" (length string)) string)
+      t
+    nil))
+
 (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))
+      (or (match-string 1 link) (kiwix-select-library "en"))
     ;; validate query is non-English
     (kiwix-select-library "zh")))
 
@@ -354,7 +360,7 @@ for query string and library interactively."
   ;; - query : should not exclude space
   (when (string-match "\\(?:(\\(.*\\)):\\)?\\([^]\n\t\r]*\\)"  link) ; 
(library):query
     (let* ((library (kiwix-org-get-library link))
-           (query (match-string 2 link))
+           (query (if (chinese-string-p link) link (match-string 2 link)))
            (url (concat
                  kiwix-server-url
                  library "/A/"



reply via email to

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