branch: externals/pyim commit f2f3197a9fcf917aebd9370577c0b0bfd47d8c23 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
* pyim-dcache.el (pyim-dcache-get): Update. --- pyim-dcache.el | 14 ++++++++------ pyim-dregcache.el | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/pyim-dcache.el b/pyim-dcache.el index bc0c9dee64..4e51d36e4a 100644 --- a/pyim-dcache.el +++ b/pyim-dcache.el @@ -205,17 +205,19 @@ dcache. * 编码 -> 词条 1. code2word 用编码搜索词条 -2. icode2word 用编码搜索个人词条 -3. ishortcode2word 用简码搜索个人词条 -4. shortcode2word 用简码搜索个人词条 +2. shortcode2word 用简码搜索词条 +3. icode2word 用编码搜索个人词条 +4. ishortcode2word 用简码搜索个人词条 * 词条 -> 编码 1. word2code 用词条搜索编码 * 词条 -> 词频 -1. iword2count 用个人词条搜索编码 -2. iword2count-recent-10-words 搜索最近输入10个词的词频 -3. iword2count-recent-50-words 搜索最近输入50个词的词频" +1. iword2count 搜索个人词条的词频 +2. iword2count-recent-10-words 搜索最近输入10个词条的词频 +3. iword2count-recent-50-words 搜索最近输入50个词条的词频 + +如果 FROM 是 nil, 那么 fallback 到 \\='(icode2word code2word)." nil) (cl-defmethod pyim-dcache-get :before (_code &optional _from) diff --git a/pyim-dregcache.el b/pyim-dregcache.el index 06641c023e..f55bedf73a 100644 --- a/pyim-dregcache.el +++ b/pyim-dregcache.el @@ -64,24 +64,34 @@ "从 FROM 中搜索 KEY, 得到对应的结果。 用于 pyim-dregcache 类型的 dcache 后端。" + (setq from (or from '(icode2word code2word))) (when key - (cond ((or (memq 'icode2word from) - (memq 'ishortcode2word from)) - (pyim-dregcache-get-icode2word-ishortcode2word key)) - ((or (not from) - (memq 'code2word from) - (memq 'shortcode2word from)) - (pyim-dregcache-get-code2word-shortcode2word key)) - ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent-10-words 和 - ;; iword2count-recent-50-words. - ((or (memq 'iword2count-recent-10-words from) - (memq 'iword2count-recent-50-words from)) - nil) - ;; pyim-dregcache 目前只能用于全拼输入法,而 pyim 中全拼输入法代码反查 - ;; 功能是通过 pymap 相关函数实现的,不使用 word2code. - ((memq 'word2code from) - nil) - (t nil)))) + (let (value result) + (dolist (x from) + (setq value (pyim-dregcache-get-key-from-dcache-type key x)) + ;; 处理 iword2count. + (unless (listp value) + (setq value (list value))) + (when value + (setq result (append result value)))) + result))) + +(defun pyim-dregcache-get-key-from-dcache-type (key dcache-type) + (cond ((memq dcache-type '(icode2word ishortcode2word)) + (pyim-dregcache-get-icode2word-ishortcode2word key)) + ((memq dcache-type '(code2word shortcode2word)) + (pyim-dregcache-get-code2word-shortcode2word key)) + ((memq dcache-type '(iword2count)) + (gethash key pyim-dregcache-iword2count)) + ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent-10-words 和 + ;; iword2count-recent-50-words. + ((memq dcache-type '(iword2count-recent-10-words iword2count-recent-50-words)) + nil) + ;; pyim-dregcache 目前只能用于全拼输入法,而 pyim 中全拼输入法代码反查 + ;; 功能是通过 pymap 相关函数实现的,不使用 word2code. + ((memq dcache-type '(word2code)) + nil) + (t nil))) (defun pyim-dregcache-get-code2word-shortcode2word (code) (when pyim-debug (message "pyim-dregcache-get-code2word-shortcode2word called => %s" code))