[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 88f65f16cf: * pyim-dhashcache.el (pyim-dhashcache-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 88f65f16cf: * pyim-dhashcache.el (pyim-dhashcache-upgrade-icode2word): Fixed. |
Date: |
Fri, 10 Jun 2022 20:57:50 -0400 (EDT) |
branch: externals/pyim
commit 88f65f16cf9c98425c63d9be84c54733442d4ca5
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
* pyim-dhashcache.el (pyim-dhashcache-upgrade-icode2word): Fixed.
---
pyim-dhashcache.el | 53 ++++++++++++++++++++++++++++++-----------------------
pyim-liberime.el | 1 -
pyim-scheme.el | 16 ++++++++--------
tests/pyim-tests.el | 17 +++++++++++++++++
4 files changed, 55 insertions(+), 32 deletions(-)
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 4ba5884225..d4ff1093a1 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -642,37 +642,44 @@ pyim 使用的词库文件是简单的文本文件,编码 *强制* 为 \\='utf
当前已有的功能:
1. 基于 :code-prefix-history 信息,升级为新的 code-prefix。"
- (pyim-dhashcache-upgrade-icode2word))
+ (pyim-dhashcache-upgrade-icode2word
+ (yes-or-no-p "Delete old key after upgrade? ")))
-(defun pyim-dhashcache-upgrade-icode2word ()
+(defun pyim-dhashcache-upgrade-icode2word (&optional delete-old-key)
"升级 icode2word 缓存。"
- (let ((delete-old-key-p (yes-or-no-p "Delete old key after upgrade? "))
- (ruler-list (delete-dups
- (remove nil
- (mapcar
- (lambda (scheme)
- (let ((code-prefix (plist-get (cdr scheme)
:code-prefix))
- (code-prefix-history (plist-get (cdr
scheme) :code-prefix-history)))
- (when code-prefix-history
- (cons code-prefix-history code-prefix))))
- pyim-schemes)))))
- (dolist (ruler ruler-list)
- (let ((old-prefix-list (car ruler))
- (new-prefix (cdr ruler)))
- (dolist (old-prefix old-prefix-list)
- (maphash
- (lambda (key _value)
- (when (string-prefix-p old-prefix key)
+ (dolist (ruler (pyim-dhashcache-upgrade-icode2word-rulers))
+ (let ((old-prefix-list (car ruler))
+ (new-prefix (cdr ruler)))
+ (dolist (old-prefix old-prefix-list)
+ (maphash
+ (lambda (key _value)
+ (if (string-prefix-p old-prefix key)
(let* ((key-words (gethash key pyim-dhashcache-icode2word))
(new-key (concat new-prefix (string-remove-prefix
old-prefix key)))
(new-key-words (gethash new-key
pyim-dhashcache-icode2word))
(merged-value (delete-dups `(,@new-key-words
,@key-words))))
(puthash new-key merged-value pyim-dhashcache-icode2word)
- (message "PYIM icode2word upgrade: %S %S -> %S %S" key
key-words new-key merged-value)
- (when delete-old-key-p
+ (message "PYIM: %S %S -> %S %S in
`pyim-dhashcache-icode2word'."
+ key key-words new-key merged-value)
+ (when delete-old-key
(remhash key pyim-dhashcache-icode2word)
- (message "PYIM icode2word upgrade: %S has been deleted."
key)))))
- pyim-dhashcache-icode2word))))))
+ (message "PYIM: %S has been deleted in
`pyim-dhashcache-icode2word'." key)))
+ (message "PYIM: No need to upgrade in
`pyim-dhashcache-icode2word'.")))
+ pyim-dhashcache-icode2word)))))
+
+(defun pyim-dhashcache-upgrade-icode2word-rulers ()
+ "返回 icode2word 升级规则。
+
+类似: (((\".\") . \"wubi/\") ((\"@\") . \"cangjie/\"))."
+ (delete-dups
+ (remove nil
+ (mapcar
+ (lambda (scheme)
+ (let ((code-prefix (pyim-scheme-code-prefix scheme))
+ (code-prefix-history (pyim-scheme-code-prefix-history
scheme)))
+ (when code-prefix-history
+ (cons code-prefix-history code-prefix))))
+ pyim-schemes))))
;; ** 保存 dhashcache 相关函数
(cl-defmethod pyim-dcache-save-caches
diff --git a/pyim-liberime.el b/pyim-liberime.el
index 638442e327..bf8049c410 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -51,7 +51,6 @@
(:constructor pyim-scheme-rime-create)
(:copier nil))
"Rime 输入法方案。"
- code-prefix-history
code-split-length
code-maximum-length)
diff --git a/pyim-scheme.el b/pyim-scheme.el
index cfae9cdabd..dc8df74add 100644
--- a/pyim-scheme.el
+++ b/pyim-scheme.el
@@ -57,13 +57,14 @@
(:constructor pyim-scheme-create)
(:copier nil))
"输入法通用方案类型."
- (name nil :type symbol :documentation "输入法名称。")
- (document nil :type string :documentation "输入法简要说明。")
- (first-chars nil :type string :documentation "输入法启动后,可以处理的第一个字符。")
- (rest-chars nil :type string :documentation "输入法处理一个字符后,可以继续处理的字符。")
- (code-prefix nil :type string :documentation "pyim 词库用到的编码前缀,比如:wubi/ 等。")
- (prefer-triggers nil :type list :documentation
"单字符快捷键设置,有些输入法不使用某个字母,这个字母就可以做为快捷键使用。")
- (cregexp-support-p nil :type boolean :documentation
"输入法是否支持从代码生成搜索中文的正则表达式。"))
+ (name nil :type symbol :documentation "输入法名称。")
+ (document nil :type string :documentation "输入法简要说明。")
+ (first-chars nil :type string :documentation "输入法启动后,可以处理的第一个字符。")
+ (rest-chars nil :type string :documentation
"输入法处理一个字符后,可以继续处理的字符。")
+ (code-prefix nil :type string :documentation "pyim
词库用到的编码前缀,比如:wubi/ 等。")
+ (code-prefix-history nil :type list :documentation
"输入法以前使用过的编码前缀,用于编写词库升级程序。")
+ (prefer-triggers nil :type list :documentation
"单字符快捷键设置,有些输入法不使用某个字母,这个字母就可以做为快捷键使用。")
+ (cregexp-support-p nil :type boolean :documentation
"输入法是否支持从代码生成搜索中文的正则表达式。"))
(cl-defstruct (pyim-scheme-quanpin
(:include pyim-scheme)
@@ -89,7 +90,6 @@
这个输入法方案类型代表那些重码少,编码长度固定的一类输入法,比如:
五笔输入法,仓颉输入法等。"
- (code-prefix-history nil :type list :documentation
"输入法以前使用过的代码前缀,用于编写词库升级程序。")
(code-split-length nil :type number :documentation "代码分割长度。")
(code-maximum-length nil :type number :documentation "代码最大长度。"))
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 0addef0d49..d1ee5fa7e0 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -1239,6 +1239,23 @@ yin-xing 因行
'((day 3 7 6 4 5 9 1)))
'(69))))
+(ert-deftest pyim-tests-pyim-dhashcache-upgrade-icode2word ()
+ (let ((pyim-dhashcache-icode2word (make-hash-table :test #'equal)))
+ (puthash ".aaaa" '("工") pyim-dhashcache-icode2word)
+ (puthash "wubi/aaaa" '("㠭" "工") pyim-dhashcache-icode2word)
+ (pyim-dhashcache-upgrade-icode2word t)
+ (should-not (gethash ".aaaa" pyim-dhashcache-icode2word))
+ (should (equal (gethash "wubi/aaaa" pyim-dhashcache-icode2word)
+ '("㠭" "工"))))
+ (let ((pyim-dhashcache-icode2word (make-hash-table :test #'equal)))
+ (puthash ".aaaa" '("工") pyim-dhashcache-icode2word)
+ (puthash "wubi/aaaa" '("㠭" "工") pyim-dhashcache-icode2word)
+ (pyim-dhashcache-upgrade-icode2word)
+ (should (equal (gethash ".aaaa" pyim-dhashcache-icode2word)
+ '("工")))
+ (should (equal (gethash "wubi/aaaa" pyim-dhashcache-icode2word)
+ '("㠭" "工")))))
+
;; ** pyim-dregcache 相关单元测试
(ert-deftest pyim-tests-pyim-general ()
(let ((pyim-dcache-backend 'pyim-dregcache))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/pyim 88f65f16cf: * pyim-dhashcache.el (pyim-dhashcache-upgrade-icode2word): Fixed.,
ELPA Syncer <=