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

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

[elpa] externals/pyim 4b7f617: 优化 shortcode 和 ishortcode 的处理过程。


From: ELPA Syncer
Subject: [elpa] externals/pyim 4b7f617: 优化 shortcode 和 ishortcode 的处理过程。
Date: Mon, 13 Dec 2021 03:57:30 -0500 (EST)

branch: externals/pyim
commit 4b7f6172e21af707b7caeaaa6139dc1379ada04a
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    优化 shortcode 和 ishortcode 的处理过程。
    
        * pyim-dhashcache.el (pyim-dhashcache-get-shortcode): do not call 
pyim-dcache-code-split.
        (pyim-dhashcache-update-icode2word): call 
pyim-dhashcache-update-ishortcode2word.
        (pyim-dhashcache-update-personal-words): Do not call 
pyim-dhashcache-update-ishortcode2word.
        (pyim-dhashcache-update-code2word): Call 
pyim-dhashcache-update-shortcode2word.
    
        * tests/pyim-tests.el (pyim-tests-pyim-dhashcache-get-shortcode): 
Updated.
    
        * pyim-dcache.el (pyim-dcache-update): do not call 
pyim-dcache-update-code2word.
        (pyim-dcache-code-split): removed.
---
 pyim-dcache.el      | 23 +----------------------
 pyim-dhashcache.el  | 15 ++++++++-------
 tests/pyim-tests.el |  6 ++----
 3 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index 324fbf1..06c4a34 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -207,9 +207,7 @@ non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式"
 如果 FORCE 为真,强制加载。"
   (pyim-dcache-init-variables)
   (pyim-dcache-update-personal-words force)
-  (pyim-dcache-update-code2word force)
-  ;; 这个命令 *当前* 主要用于五笔输入法。
-  (pyim-dcache-update-shortcode2word force))
+  (pyim-dcache-update-code2word force))
 
 (defun pyim-dcache-update-code2word (&optional force)
   "读取并加载词库.
@@ -291,25 +289,6 @@ code 对应的中文词条了."
   `(,@(pyim-dcache-call-api 'get code from)
     ,@(pyim-pymap-py2cchar-get code t t)))
 
-;; ** 分割 code
-(defun pyim-dcache-code-split (code)
-  "将 CODE 分成 code-prefix 和 rest code."
-  (cond
-   ;; 处理 nil
-   ((not code) nil)
-   ;; 兼容性代码:旧版本的 pyim 使用一个标点符号作为 code-prefix
-   ((pyim-string-match-p "^[[:punct:]]" code)
-    (list (substring code 0 1) (substring code 1)))
-   ;; 拼音输入法不使用 code-prefix, 并且包含 -
-   ((pyim-string-match-p "-" code)
-    (list "" code))
-   ((not (pyim-string-match-p "[[:punct:]]" code))
-    (list "" code))
-   ;; 新 code-prefix 使用类似 "wubi/" 的格式。
-   (t (let ((x (split-string code "/")))
-        (list (concat (nth 0 x) "/")
-              (nth 1 x))))))
-
 ;; * Footer
 (provide 'pyim-dcache)
 
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 9f64161..c81155e 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -66,10 +66,10 @@
   "获取一个 CODE 的所有简写.
 
 比如:.nihao -> .nihao .niha .nih .ni .n"
-  (when (and (> (length code) 0)
-             (not (string-match-p "-" code)))
-    (let* ((x (pyim-dcache-code-split code))
-           (prefix (nth 0 x))
+  (when (and (pyim-string-match-p "/" code)
+             (not (pyim-string-match-p "-" code)))
+    (let* ((x (split-string code "/"))
+           (prefix (concat (nth 0 x) "/"))
            (code1 (nth 1 x))
            (n (length code1))
            results)
@@ -256,6 +256,7 @@ DCACHE 是一个 code -> words 的 hashtable.
        (lambda (_)
          (pyim-dcache-set-variable 'pyim-dhashcache-code2word t)
          (pyim-dcache-set-variable 'pyim-dhashcache-word2code t)
+         (pyim-dhashcache-update-shortcode2word force)
          (setq pyim-dhashcache-update-code2word-running-p nil))))))
 
 (defun pyim-dhashcache-export (dcache file &optional confirm)
@@ -328,7 +329,8 @@ code 对应的中文词条了。
         (pyim-dcache-save-variable 'pyim-dhashcache-icode2word)
         nil)
      (lambda (_)
-       (pyim-dcache-set-variable 'pyim-dhashcache-icode2word t)))))
+       (pyim-dcache-set-variable 'pyim-dhashcache-icode2word t)
+       (pyim-dhashcache-update-ishortcode2word force)))))
 
 (defun pyim-dhashcache-upgrade-icode2word ()
   "升级 icode2word 缓存。"
@@ -361,8 +363,7 @@ code 对应的中文词条了。
            pyim-dhashcache-icode2word))))))
 
 (defun pyim-dhashcache-update-personal-words (&optional force)
-  (pyim-dhashcache-update-icode2word force)
-  (pyim-dhashcache-update-ishortcode2word force))
+  (pyim-dhashcache-update-icode2word force))
 
 (defun pyim-dhashcache-init-variables ()
   "初始化 dcache 缓存相关变量."
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index a8cf903..c75fb31 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -598,12 +598,10 @@
 
 ;; ** pyim-dhashcache 相关单元测试
 (ert-deftest pyim-tests-pyim-dhashcache-get-shortcode ()
-  (should (equal (pyim-dhashcache-get-shortcode ".abcde")
-                 '(".abcd" ".abc" ".ab")))
+  (should (equal (pyim-dhashcache-get-shortcode ".abcde") nil))
   (should (equal (pyim-dhashcache-get-shortcode "wubi/abcde")
                  '("wubi/abcd" "wubi/abc" "wubi/ab")))
-  (should (equal (pyim-dhashcache-get-shortcode "abcde")
-                 '("abcd" "abc" "ab")))
+  (should (equal (pyim-dhashcache-get-shortcode "abcde") nil))
   (should (equal (pyim-dhashcache-get-shortcode "ni-hao") nil))
   (should (equal (pyim-dhashcache-get-shortcode "") nil)))
 



reply via email to

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