[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 0374544: Add pyim-dcache-upgrade-icode2word.
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 0374544: Add pyim-dcache-upgrade-icode2word. |
Date: |
Tue, 4 May 2021 08:57:11 -0400 (EDT) |
branch: externals/pyim
commit 0374544cb91529a1c3ba739db70880b9e1298716
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-dcache-upgrade-icode2word.
* pyim-dcache.el (pyim-dcache-upgrade-icode2word): New function.
* pyim-dhashcache.el (pyim-dhashcache-upgrade-icode2word): New function.
---
README.org | 3 ++-
pyim-dcache.el | 9 +++++++++
pyim-dhashcache.el | 27 +++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index a9180b6..3c355be 100644
--- a/README.org
+++ b/README.org
@@ -20,10 +20,11 @@ code-prefix.
1. 五笔用户
1. 需要 (require 'pyim-wbdict), 加载五笔 scheme 设置。
2. 需要将自己的五笔词库文件中的 code-prefix "." 替换为 "wubi/".
+ 3. 运行 `pyim-dcache-upgrade-icode2word' 命令,升级个人词库。
2. 仓颉用户
1. 需要 (require 'pyim-cangjie5dict), 加载仓颉 scheme 设置。
2. 需要将自己的五笔词库文件中的 code-prefix "@" 替换为 "cangjie/".
-
+ 3. 仓颉输入法不使用个人词库,所以不需要运行 `pyim-dcache-upgrade-icode2word'.
* 截图
[[file:./snapshots/pyim-linux-x-with-toolkit.png]]
diff --git a/pyim-dcache.el b/pyim-dcache.el
index 5edac36..3dbbb9c 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -292,6 +292,15 @@ MERGE-METHOD 是一个函数,这个函数需要两个数字参数,代表
"保存个人词到缓存."
(pyim-dcache-call-api 'insert-word-into-icode2word word pinyin prepend))
+;; ** Dcache 升级功能
+(defun pyim-dcache-upgrade-icode2word ()
+ "升级个人词库缓存.
+
+主要是将个人词库中旧的 code-prefix 升级为新的 code-prefix. 用到
+scheme 中的 :code-prefix-history 信息。"
+ (interactive)
+ (pyim-dcache-call-api 'upgrade-icode2word))
+
;; ** Dcache 删词功能
(defun pyim-dcache-delete-word (word)
"将中文词条 WORD 从个人词库中删除"
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 9f1fd41..830fcb5 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -35,6 +35,7 @@
;; * 代码 :code:
(require 'pyim-common)
(require 'pyim-dcache)
+(require 'pyim-scheme)
(require 'async nil t)
;; Pyim 词库缓存文件,注意:变量名称中不能出现 ":" 等,不能作为文件名称的字符。
@@ -323,6 +324,32 @@ code 对应的中文词条了。
(setq pyim-dhashcache-update-icode2word-p t)
(pyim-dcache-set-variable 'pyim-dhashcache-icode2word t)))))
+(defun pyim-dhashcache-upgrade-icode2word ()
+ "升级 icode2word 缓存。"
+ (let ((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)
+ (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 `(,@key-words
,@new-key-words))))
+ (puthash new-key merged-value pyim-dhashcache-icode2word)
+ (message "PYIM icode2word upgrade: %S %S -> %S %S\n" key
key-words new-key new-key-words))))
+ pyim-dhashcache-icode2word))))))
+
(defun pyim-dhashcache-update-personal-words (&optional force)
(pyim-dhashcache-update-icode2word force)
(pyim-dhashcache-update-ishortcode2word force))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/pyim 0374544: Add pyim-dcache-upgrade-icode2word.,
ELPA Syncer <=