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

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

[elpa] externals/pyim 8672b90 1/2: Add pyim-zip.


From: ELPA Syncer
Subject: [elpa] externals/pyim 8672b90 1/2: Add pyim-zip.
Date: Sat, 4 Dec 2021 21:57:35 -0500 (EST)

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

    Add pyim-zip.
    
        * pyim-common.el (pyim-zip): Added.
        * pyim-candidates.el (pyim-candidates-create:quanpin): Use pyim-zip.
        (pyim-candidates-merge): Removed
---
 pyim-candidates.el | 26 +++++++-------------------
 pyim-common.el     | 12 ++++++++++++
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/pyim-candidates.el b/pyim-candidates.el
index 3bb2b02..a05e483 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -126,9 +126,13 @@ IMOBJS 获得候选词条。"
                ;; 第一个汉字
                (w3 (pyim-dcache-get
                     (car (pyim-codes-create imobj scheme-name)))))
-          (setq personal-words (pyim-candidates-merge personal-words w1))
-          (setq common-words (pyim-candidates-merge common-words w2))
-          (setq pinyin-chars (pyim-candidates-merge pinyin-chars w3))))
+          (push w1 personal-words)
+          (push w2 common-words)
+          (push w3 pinyin-chars)))
+
+      (setq personal-words (pyim-zip (nreverse personal-words)))
+      (setq common-words (pyim-zip (nreverse common-words)))
+      (setq pinyin-chars (pyim-zip (nreverse pinyin-chars)))
 
       ;; 个人词条排序:使用词频信息对个人词库得到的候选词排序,第一个词条的位置
       ;; 比较特殊,不参与排序,具体原因请参考 `pyim-page-select-word' 中的
@@ -155,22 +159,6 @@ IMOBJS 获得候选词条。"
                ,@znabc-words
                ,@pinyin-chars))))))
 
-(defun pyim-candidates-merge (list1 list2)
-  "将 LIST1 和 LIST2 合并。
-
-如果 list1 = (a b), list2 = (c d e),
-那么结果为: (a c b d e)."
-  (let ((list1 (delete-dups list1))
-        (list2 (delete-dups list2))
-        result)
-    (while (and list1 list2)
-      (push (pop list1) result)
-      (push (pop list2) result))
-    (if (or list1 list2)
-        `(,@(nreverse result)
-          ,@(or list1 list2))
-      (nreverse result))))
-
 (defun pyim-candidates-create:shuangpin (imobjs _scheme-name &optional async)
   "`pyim-candidates-create' 处理双拼输入法的函数."
   (pyim-candidates-create:quanpin imobjs 'quanpin async))
diff --git a/pyim-common.el b/pyim-common.el
index 0452596..f794291 100644
--- a/pyim-common.el
+++ b/pyim-common.el
@@ -85,6 +85,18 @@
                       append (mapcar (lambda (l) (cons element l))
                                      (pyim-permutate-list list-tail)))))))
 
+(defun pyim-zip (lists)
+  "Zip LISTS: ((a b c) (d e)) => (a d b e c)."
+  (let* ((n (apply #'max (mapcar #'length lists)))
+         (lists (mapcar
+                 (lambda (x)
+                   (append x (make-list (- n (length x)) nil)))
+                 lists)))
+    (flatten-tree
+     (apply #'cl-mapcar
+            (lambda (&rest x) x)
+            lists))))
+
 (defun pyim-char-before-to-string (num)
   "得到光标前第 `num' 个字符,并将其转换为字符串。"
   (let* ((point (point))



reply via email to

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